一、概念
二、代码示例
#include <iostream>
using namespace std;
class Parent
{
protected:
const char *Name;
public:
Parent()
{
Name = "Parent";
}
void print()
{
cout<<"Name: "<<Name<<endl;
}
};
class Child:public Parent
{
protected:
int i;
public:
Child(int i)
{
this->i = i;
Name = "Child";
}
};
int main(int argc, char *argv[])
{
Child child(100);
Parent parent = child;
Parent *pp = &child;
Parent &rp = child;
parent.print();
pp->print();
rp.print();
return 0;
}