【发布时间】:2010-10-14 21:58:30
【问题描述】:
假设我的课程 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;
}
};
正如代码中所注释的那样,我希望能够调用我正在覆盖的基类函数。在 Java 中有 super.funcname() 语法。这在 C++ 中可行吗?
【问题讨论】:
-
对于 Google 员工:请注意,您可能会遇到像我一样将其存储为非指针的类成员变量的问题。在这里查看我的答案:stackoverflow.com/questions/4798966/…我参与了 new/delete 来修复。
标签: c++ virtual-functions overriding