【发布时间】:2012-04-01 05:38:20
【问题描述】:
我有一些这样的活动
class Granpa // this would not be changed, as its in a dll and not written by me
{
public:
virtual void onLoad(){}
}
class Father :public Granpa // my modification on Granpa
{
public:
virtual void onLoad()
{
// do important stuff
}
}
class Child :public Father// client will derive Father
{
virtual void onLoad()
{
// Father::onLoad(); // i'm trying do this without client explicitly writing the call
// clients code
}
}
有没有办法强制调用 onLoad 而无需实际编写 Father::onLoad()?
欢迎使用黑客解决方案 :)
【问题讨论】:
-
我不明白为什么这是个问题。你想明确地做某事,所以你需要在代码中明确地说出来……
-
不添加一行代码来做你想明确发生的事情是不是有点懒惰?
-
由于在 ie MFC 处理程序中没有解决相同的问题(您总是需要从您的 CMyDialog::OnInitDialog() 显式调用 CDialog::OnInitDialog()),我认为您可以只要求用户这样做。
-
我同意@OliCharlesworth,我几乎看不出这是个问题。如果客户端想调用它,他会显式调用它。
-
如果没有强制调用的解决方案,我将添加他们应该调用它的文档。最好不要让客户的事情变得过于复杂。
标签: c++ class function inheritance virtual