void is invalid? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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