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