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