+ 2
In the below program How can i print the name value on the screen?
#include <iostream> #include <string> using namespace std; class myClass { public: void setName(string x) { name = x; } private: string name; }; int main() { myClass myObj; myObj.setName("John"); return 0; }
2 ответов
+ 2
You need to add a function to get the name of myClass.
+ 1
If the 'name' variable were public, it would be easy.
In this case, a getter method is what you need.