Hi All,
I am new to OOP. I am trying to do something similar like the following code (using inheritance).
Code:class Person { public: Person () { cout << "Person: constructor\n"; } void talk() { cout << "Person: talk\n"; } void walk() { cout << "Person: walk\n"; } }; class Boy : public Person { public: Boy () { cout << "Boy: constructor\n"; } void gotoFootball() { cout << "Boy: football\n"; } }; class Girl : public Person { public: Girl () { cout << "Girl: constructor\n"; } void gotoDance() { cout << "Girl: dance\n"; } };
then in the main function, have the following code
this however doesn't compile as gotoFootball is not recognized by Person. Is it possible to achieve something like this please? Also I know this is a 'stupid' example but I tried to keep it simple till I understand how it works.Code:Person *p1; p1 = new Boy(); p1->gotoFootball();
Thanks![]()




Reply With Quote