假设我有这样设置的类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++中可行吗?