+ 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; }

24th Mar 2017, 7:59 PM
Tae
2 Respuestas
+ 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).
24th Mar 2017, 9:00 PM
Squidy
Squidy - avatar
0
+1
24th Mar 2017, 11:31 PM
Tae