Hello :). How can I fix this?
Yes, I can write 2 functions (with and without parameter) ... but what is bad there?
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
class CClass{
public:
void foo(string & s = "default"); // COMPILE ERROR
string backup;
};
void CClass::foo(string & s){
backup = s;
}
int main(int argc, char const *argv[]){
CClass myClass;
cout << myClass.backup << endl;
myClass.foo ();
cout << myClass.backup << endl;
string str = "amazing world";
myClass.foo (str);
cout << myClass.backup << endl;
return 0;
}
Thanks :).