派生类的方法疑问
#include <iostream.h>class CRoot{
public:
int small;
CRoot()
{small= 2; }
CRoot(int n)
{ small = n;}
void showsmall()
{ cout<<"small="<<small<<endl; }
};
class CDer1:public CRoot
{
public:
CDer1(int m):CRoot(m) { }
};
class CDer2:public CRoot
{
public:
int small;
CDer2(int n=0) {small=n; }
};
void main()
{ CRoot A;
CDer1 B(3);
CDer2 C;
A.showsmall(); B.showsmall(); C.showsmall();
}
运行结果:
为什么是small=2
small=3
small=2