I have the following situation, I declared a const
member of a superclass and now I want to initialize it within the the constructor of one of its subclasses using a list initializer.
struct Shape {
public:
const Rect boundingRect; // the rect in which the shape is contained
};
struct Stain : Shape
{
public:
Stain(Rect boundingRect_) : boundingRect(boundingRect_) {}
};
I am not sure if this is even possible, if I take the straightforward approach shown above, the compiler complains with the following message:
member initializer 'boundingRect' does not name a non-static data member or base class
This answer explains why it's not possible to initialize member variables of a superclass in list initiliazers of a subclass's constructor. I am wondering what the best practice might be for that situation?