0

Function used before being declared?

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" why don't we get an error here, because the function setName is used before being declared.

1st Jun 2018, 2:37 PM
Kasul Kliff
Kasul Kliff - avatar
0 Respuestas