For example, if I have a class like this:
class Widget {
public:
virtual void Init(); // In this function, call some virtual function
// to construct the object
void Paint(); // Deprecated, use paintWidget instead
void PaintWidget(); // A new implementation of paint
... // Other stuff, including a virtual function
// which need to be called to construct the object
}
The construction of a Widget
requires a virtual function call (that's why I wrote the Widget::Init()
). Is there a way to make a constraint on Widget::Init()
so that it must be called before any use of the object, and raise error if the user violates the constraint? Another problem is creating a customize warning message for a deprecated method. With the code above, if a user of my class calls Widget::paint()
, how can I tell them to use Widget::paintWidget()
instead of deprecated Widget::paint()
, and tell them about the consequence of using the deprecated one? Thank you.