In the program below, we copy a reference from cDerived to rBase with "Base &rBase = &cDerived;" But why doesn't it use a pointer instead? Wouldn't it make more sense to do the following: "Base *rBase = &cDerived;" since a pointer is what points to an address.
class Base
{
protected:
public:
virtualconstchar* GetName() { return"Base"; }
};
class Derived: public Base
{
public:
virtualconstchar* GetName() { return"Derived"; }
};
int main()
{
Derived cDerived;
Base &rBase = &cDerived;
cout << "rBase is a " << rBase.GetName() << endl;
return 0;
}
# output:
rBase is a Derived