Here's the corrected code.
#include
using namespace std;
class A{
int val;
public:
A(int val){
this->val=val;
}
};
class B{
A a;
public:
B(A& x):a(x) {
}
};
int main(){
A tempa(3);
B tempb(tempa);
}
Corrections are:
1. Both Constructors of A and B should be public
2. Instead of assignment, let B constructor call A's copy constructor