0
What is an example of the constructor
I'm not sure what a constructor looks like can you please point it out here class myClass { public: myClass(string nm) { setName(nm); } void setName(string x) { name = x; } string getName() { return name; } private: string name; }; int main() { myClass ob1("David"); myClass ob2("Amy"); cout << ob1.getName(); } //Outputs "David"
1 ответ
0
here myClass(string) is a constructor
name of class and constructor is same and constructor do not have any return type.