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
}
构建小部件(Widget)需要进行虚函数调用(这就是为什么我编写了 Widget::Init() 的原因)。是否有一种方法可以对 Widget::Init() 进行约束,使其在对象的任何使用之前必须被调用,并且如果用户违反约束,则引发错误?另一个问题是创建自定义警告消息以针对已弃用的方法。在上面的代码中,如果我的类的用户调用 Widget::paint(),如何告诉他们使用已弃用的 Widget::paint() 代替,并告知他们使用已弃用的方法的后果?谢谢。