0
Help me
Can anybody help me to understand this program #include <iostream> #include <string> using namespace std; class myClass { public: void setName(string x) { name = x; } string getName() { return name; } private: string name; }; int main() { myClass myObj; myObj.setName("John"); cout << myObj.getName(); return 0; }
1 Resposta
+ 3
Its encapsulation. You access to a private class member (name , in this case) , using methods (get and set).
get will return the name, and set will assign a new value.
You can do myObj.name = "something", because you can't access to a private member outside the class.