Possible Duplicate:
Nonstatic member as a default argument of a nonstatic member function
Ok. So I'm having problems understanding how to accomplish a seemingly simple task... Here is what I want to accomplish:
#include <iostream>
using namespace std;
class A{
private:
int _x;
public:
A(int x){
_x = x;
}
void test(int x=_x){
cout << x << endl;
}
};
int main(){
A a(3);
a.test();
}
The compiler complains about the int x=_x
part saying error: invalid use of non-static data member A::_x
So how do I use a default parameter like this?
Thanks.