

cpp
#include <iostream>
using namespace std;
class RemoteCon{
public:
virtual void openUtils()
{
cout<<"base:open "<<endl;
}
};
class TvRemoteCon:public RemoteCon{
public:
void openUtils () override
{
cout<<"TV open "<<endl;
}
};
class LightCon:public RemoteCon{
public:
void openUtils () override
{
cout<<"Light open "<<endl;
}
};
void test(RemoteCon &base)
{
base.openUtils();
}
int main()
{
//父类的指针指向子类的对象
RemoteCon *r = new TvRemoteCon;
r->openUtils();
RemoteCon *r1 = new LightCon;
r1->openUtils();
//父类的引用指向子类的对象
TvRemoteCon tv;
test(tv);//RemoteCon &base = tv
return 0;
}
