#include<iostream.h>
class A{ int x; A(int a){x=a;}
public: void setA(int y){x=y;}
};
class B:private A{
public: B(){cout<<"B"<<endl;}
};
void main()
{ A a1(2),a2; A a3=a2; B b; b.set(3);
}
#include<iostream.h>
class A
{ int x;
public: A(){} A(int a){x=a;} void setA(int y){x=y;}
};
class B:public A
{
public: B(){cout<<"B"<<endl;}
};
void main()
{ A a1(2),a2; A a3=a2; B b; b.setA(3);
}
构造函数只能声明为public。当自己定义了构造函数时,系统就不提供无参构造函数。当需要调用无参构造函数时,就要自己定义啦!小伙子好好学哈!别那么粗心啦!