Is there a way you can invoke a member function of a base class upon a class derived from it?
Class Bass{
public:
void func();
};
Class Derived: public Base{
public:
void func();
};
I have a practice midterm, and I suspect no, because how would the Base class know about the Derived, but I am not sure.
Not sure exactly what you mean by this, but given your
BaseandDerivedclasses you can do the following. Just make sure you use a reference or pointer, not pass-by-value because of the slicing problem.Call
Base::func()from withinDerived::func():Call
Base::func()explicitly on aDerivedobject:As others have pointed out, you can do this using a forward declaration:
However, you won’t be able to define the
Base::func(Derived&)directly in the class definition since you need to finished definingBaseand to defineDerivedfirst.