Now we can finally come back to the colored body...
Recall that we had problems with the const keywords because we were violating the contract. All the problems came from the pointer to the “color” object, which we can eliminate now.
We also implement the copy constructor, the assignment operator, all const keywords, and are basically set.
// the constructors for body
// the member functions we already know
virtual float GetVolume() const =0;
virtual float GetSurface() const =0;
// two more functions which deal with the color
virtual void setColor (const Color &c);
virtual Color * getColor() const;
We now pass the Color object as a reference and no longer as a pointer.
By way of the assignment operator, we make a copy of the color and are no longer in danger of violating the contract (we cannot inadvertently modify the constant color object we got).
// the constructor setting a color
body::body(const Color &c)
// we assign our color the color provided.
// now the color-handling
void body::setColor (const Color &c)