假设我有课程Foo并Bar设置如下:
class Foo
{
public:
int x;
virtual void printStuff()
{
std::cout << x << std::endl;
}
};
class Bar : public Foo
{
public:
int y;
void printStuff()
{
// I would like to call Foo.printStuff() here...
std::cout << y << std::endl;
}
};
Run Code Online (Sandbox Code Playgroud)
正如在代码中注释的那样,我希望能够调用我所覆盖的基类函数.在Java中有super.funcname()语法.这在C++中是否可行?
在C++中创建私有方法虚拟的优点是什么?
我在开源C++项目中注意到了这一点:
class HTMLDocument : public Document, public CachedResourceClient {
private:
virtual bool childAllowed(Node*);
virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
};
Run Code Online (Sandbox Code Playgroud)