c++ - Unable to call public method of the base class from a child's instance -
i wanted try constructor inheritance in c++ , worked fine. found can't call method instance of daughter class. visual studio says
the method mother::showname not available
even though public, far concerned must available child class. there doing wrong?
class mother{ protected: char* name; public : mother(char* _name){ name = _name; } void showname(){ cout << "my name is: " << name << endl; } }; class daughter : mother{ public: daughter(char* _name) : mother(_name) { } }; int main(){ daughter d1("masha"); d1.showname(); return 0; }
class daughter : mother
private
inheritance. class
inheritance default.
class daughter : public mother
you're looking for.
Comments
Post a Comment