> am I having too many constructors in my child class?
You could use default values for constructor parameters.
1 2 3 4 5 6
|
class Cube :public ThreeDimensionalShape
{
public:
explicit Cube( double side = 1.0 ) ; // default constructor
// ...
}
|
;
> In the two intermediate classes "TwoDimensionalShape" and ThreeDimensionalShape". in my header file I declared "virtual void display() const = 0; " and it compiles. Then I removed it and it still compiles. Which one is the correct declaration, with or without?
Without.
display()
is an abstract polymorphic operation on
Shape
; override it only in classes that implement it.
It doesn't make sense to put the base class and all the derived classes into the same component; you don't get any loose coupling. Define them in separate components: shape.h, shape.cc, TwoDimensionalShape.h, TwoDimensionalShape.cc, Circle.h, Circle.cc etc.
If a TwoDimensionalShape is a Shape that has an area, but no volume, shouldn't Circle be deriving from TwoDimensionalShape?