T
thomas
Hi,
------------code--------------------------------------
#include<iostream>
using namespace std;
class B{
int y;
public:
B(int b=3):y(b){}
int getInt(){
return y;
}
};
class A{
int x;
public:
A(const int &x_){ //Line 1
x=x_;
}
A(B *b){
A(b->getInt()); //Line 2
}
int getInt(){
return x;
}
};
int main(){
B *b = new B;
A *a = new A(b);
cout<<a->getInt()<<endl;
}
------------code--------------------------------------
#include<iostream>
using namespace std;
class B{
int y;
public:
B(int b=3):y(b){}
int getInt(){
return y;
}
};
class A{
int x;
public:
A(const int &x_){ //Line 1
x=x_;
}
A(B *b){
A(b->getInt()); //Line 2
}
int getInt(){
return x;
}
};
int main(){
B *b = new B;
A *a = new A(b);
cout<<a->getInt()<<endl;
}