+ 1
void is invalid?
#include <iostream> #include <string> using namespace std; class myClass { private: string name; public: void setName(); string getName(); }; void myClass::setName(string x) { name = x; } string myClass::getName() { return name; } int main() { myClass myObj; myObj.setName("Daniel"); cout << myObj.getName(); return 0; }
2 Antworten
+ 4
You've got the declaration of setName as a function not taking any parameters, and then you define it as a function taking one parameter.
In myClass, change the declaration of setName to setName(string).
0
+1