0

Please answer: what is included in <string>. What is string x?Why void is used with set name? What is set name? Why name=x?

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

14th Jan 2017, 5:20 PM
Black Temple
Black Temple - avatar
1 Resposta
+ 2
you include <string> to use the string data type and its easier than using an array of chars, void is used cause theres no value to return that function is only used to give the value of x to the name variable and setName is the name of the function
14th Jan 2017, 5:30 PM
Kawaii
Kawaii - avatar