c++ default parameters -
possible duplicate:
nonstatic member default argument of nonstatic member function
ok. i'm having problems understanding how accomplish seemingly simple task... here want 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(3); a.test(); } the compiler complains int x=_x part saying error: invalid use of non-static data member a::_x
so how use default parameter this?
thanks.
you can't that.
you can have overload test takes no parameters.
void test(){ test(_x); }
Comments
Post a Comment