0
Can someone explain the code after "int main()". What exactly is happening in the " int main" function
#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; }
5 Antworten
+ 6
an object called "myObj" is created inside the class "myClass" and its "setName" method is triggered...
+ 5
Yes it is. It means that it accepts strings and not numbers..
+ 1
It's creating an object of 'myClass', then setting the name of the that object be "John"
0
thanks a lot both of you 😊
can you please explain- void setName(string x).
what is (string x)? and what of the word string? is it a data type ?
0
thanks a lot. it helped