class first{
int fa,fb;
public:
first();
first(int x,int y);
void display();
};
first::first():fa(0),fb(0){
}
first::first(int x,int y):fa(x),fb(y){
}
void first::display(){
cout<<fa<<" "<<fb;
}
class second{
first f;
int sa,sb;
public:
second();
second(int x,int y,int a,int b);
void display();
};
second::second():sa(0),sb(0){
}
second::second(int x,int y,int a,int b):f(x,y),sa(a),sb(b){
}
void second::display(){
cout<<"The Numbers are ";
f.display();
cout<<" "<<sa<<" "<<sb<<endl;
}
如果已经提出此问题,请致歉。对象定义后调用构造函数定义
这是一个演示C++中嵌套类的工作的简单代码。 但是,在类second
,对象f
,即使它已被定义之前,我可以使用second
类的construtor调用它的构造函数。 如何在已经定义的类的实例上调用构造函数?
嵌套类或内部类是别的东西。这里你只是有作文。 – aschepler
这里没有嵌套类。 – DeiDei