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

21st Jan 2017, 4:11 PM
Black Temple
Black Temple - avatar
5 Antworten
+ 6
an object called "myObj" is created inside the class "myClass" and its "setName" method is triggered...
21st Jan 2017, 4:15 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
Yes it is. It means that it accepts strings and not numbers..
21st Jan 2017, 5:24 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
It's creating an object of 'myClass', then setting the name of the that object be "John"
21st Jan 2017, 4:18 PM
Aaron
Aaron - avatar
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 ?
21st Jan 2017, 5:22 PM
Black Temple
Black Temple - avatar
0
thanks a lot. it helped
21st Jan 2017, 5:25 PM
Black Temple
Black Temple - avatar