help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Default argument in class member function


From: Long Li
Subject: Default argument in class member function
Date: Fri, 28 Oct 2005 04:38:48 +0800 (CST)

Hi,

See these two small codes:

First one:

#include <iostream>
using std::cout;
using std::endl;

void printargu( int a = 0 ){
  cout << a << endl;
}

int main(){
  printargu();
}


Second one:

#include <iostream>
using std::cout;
using std::endl;

class da{
public:
  void printargu( int a = 0 );
};

void da::printargu( int a = 0 ){
  cout << a << endl;
}

int main(){
  da.printargu();
}

I can compile the first one and get the right result. 
However, for the second one, there are errors:
c.cpp:10: error: default argument given for parameter
1 of 'void da::printargu(int)'
c.cpp:7: error: after previous specification in 'void
da::printargu(int)'
c.cpp: In function 'int main()':
c.cpp:15: error: expected unqualified-id before '.'
token

I just put the function "printargu" in the class in
the seond code, I can't understand it.  BTW, I use
g++-4.0 in Debian testing.

Long


        

        
                
___________________________________________________________ 
雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 
http://cn.mail.yahoo.com





reply via email to

[Prev in Thread] Current Thread [Next in Thread]