0

Still dont understand this code

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

29th Sep 2019, 10:09 AM
NANA NYANTAKYI ADOMAKO
1 Answer
0
Like I thought if you set a string name to private its not supposed to display output but this this one displays an output of john
29th Sep 2019, 11:03 AM
NANA NYANTAKYI ADOMAKO