Hi, I'm not sure I understand my teacher properly, but he wants me to use the CCTOR of class CPt in the CCTOR of class CCanvas to fill a dynamically allocated array. I'm at a loss of how to call it...maybe a little code will help this make more sense:
// Function name : CCanvas()
// Description : CTOR - initializes all values, allocates all memory
// for the line data, then deep copies all members
// Argument : CCanvas const & -> canvas class reference to copy from
CCanvas::CCanvas(CCanvas const & rCanvas): _iSize(rCanvas._iSize)
{
//allocate the array of points
_cptPoints = new CPt [_iSize];
//iterate and copy all coordinates, and set color to green
for (int i(0); i < _iSize; ++i)
{
//*******Problem starts here
//**not allowed to use = operand
_cptPoints[i] = CPt(rCanvas._cptPoints[i]);
//_cptPoints[i]._iX = rCanvas._cptPoints[i]._iX;
//_cptPoints[i]._iY = rCanvas._cptPoints[i]._iY;
//_cptPoints[i]._COLOR = GREEN;
}
}
That's the CCanvas CCTOR, which needs to call CPt's CCTOR instead of leveraging off of the = operator like in the comment. And since the = operator in CPt makes the color red, the non-commented line first calls the CCTOR and that returns the proper value, but then it runs into the = operator and turns red! Here's the operator= and the CCTOR in the CPt class:
// Function name : operator=()
// Description : overloaded assignment operator - does basically
// the same thing as the CCTOR, only with the = op
// Argument : CPt const & RHS - right hand side reference, used
// for copying
// Returns : CPt -> passed by value
CPt & CPt::operator=(CPt const & RHS)
{
_iX = RHS._iX;
_iY = RHS._iY;
_COLOR = RED;
return *this;
}
// Function name : CPt()
// Description : CCTOR - assigns the coodinates of the point to
// the argument's, and sets the color to green
// Argument : CPt const & temp -> temp CPt reference to copy from
CPt::CPt(CPt const & temp):_iX(temp._iX), _iY(temp._iY), _COLOR(GREEN)
{
}
I know this might take a while to read, but I'm really stuck! Help would be much appreciated. Feel free to ask any questions (possibly about the rest of the code).