This is a question earlier asked by me. I'm getting compilation errors using the copy constructor suggested by the forum.
class A
{
private:
int a;
int b;
public:
A() { a = 0; b = 0; }
int getA() { return a; }
int getB() { return b; }
A(const Beta& b) :a{ *b.X() }, b{ *b.Y } {}
};
class Beta
{
private:
int *x;
int *y;
public:
Beta(int a, int b) { x =&a; y = &b; }
int* X() { return x; }
int* Y() { return y; }
};
int main()
{
B aObject;
Alpha a1 = aBObject;
Alpha a2;
a2 = aBObject;
return 0;
}
Without const Alpha(Beta& be) in the copy constructor argument
Error C2061 syntax error: identifier 'Beta'
Error C2228 left of '.getY' must have class/struct/union
Error C2228 left of '.getX' must have class/struct/union
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'Beta' (or there is no acceptable conversion)
Error C2440 'initializing': cannot convert from 'Beta' to 'Alpha'
Error C2065 'be': undeclared identifier
Error C2535 'Alpha::Alpha(void)': member function already defined or declared
With const Alpha(const Beta& be) in the copy constructor argument
Error (active) the object has type qualifiers that are not compatible with the member function "Beta::getX"
Error (active) the object has type qualifiers that are not compatible with the member function "Beta::getY"
Error C2061 syntax error: identifier 'Beta'
Error C2228 left of '.getY' must have class/struct/union
Error C2228 left of '.getX' must have class/struct/union
Error C2679 binary '=': no operator found which takes a right-hand operand of type 'Beta' (or there is no acceptable conversion)
Error C2440 'initializing': cannot convert from 'Beta' to 'Alpha'
Error C2065 'be': undeclared identifier
Error C2535 'Alpha::Alpha(void)': member function already defined or declared
Alpha(const Beta& be)is not a copy constructor. Beta needs to be declared before Alpha can use it.