Function used before being declared? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers