a question about const and inheritance

Suppose I have a base class called "Shape" and two sub-classes "Square" and "Triangle" which each publicly inherit from Shape. The shape class has public field called "color". Now suppose it is the case that
1. all squares are blue and never change color
and
2. triangles can be red or blue and may change color

How should this be expressed in C++? Is there a way to state that a non-const field inherited from a base class is const for one particular subclass?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories