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
ます。既に定義されているクラスのインスタンスでコンストラクターを呼び出すにはどうすればよいですか?