#include <iostream>
using std::cout;
using std::endl;
class BASE
{
public:
BASE(int n):m_b(n){}
~BASE(){}
void print(){cout<<"BASE : m_b = "<<m_b<<endl;}
private:
int m_b;
};
class DERIVED : public BASE
{
public:
DERIVED(int n):m_d(n),BASE(2*n){}
~DERIVED(){}
void print(){cout<<"DERIVED : m_d= "<<m_d<<endl;}
private:
int m_d;
};
int main()
{
DERIVED derived(4);
BASE &base=derived;
base.print();
return 0;
}
执行的语句:void print(){cout<<"BASE : m_b = "<<m_b<<endl;}