>>The error occurs on the constructor
... which you haven't posted for us. So, here's some working code for your to look at:
Code:
#include <iostream>
struct Position
{
int X;
int Y;
//Position& operator = (const Position &rhs)
//{
// /* This function is not needed,
// * the default assignment operator
// * will do the same job
// */
// X = rhs.X;
// Y = rhs.Y;
// return *this;
//}
Position (int x, int y) : X(x), Y(y) {}
};
class C
{
private:
Position myPos;
public:
C(int A, int B) : myPos(A, B) { };
int X(void) const
{
return(myPos.X);
}
int Y(void) const
{
return(myPos.Y);
}
};
int main(void)
{
C c1(1, 2), c2(3, 4);
std::cout << "c1: " << c1.X() << " " << c1.Y() << std::endl;
std::cout << "c2: " << c2.X() << " " << c2.Y() << std::endl;
c1 = c2;
// Prove assignment worked:
std::cout << "c1: " << c1.X() << " " << c1.Y() << std::endl;
return(0);
}