In Bar
, Foo
's virtual void printStuff
is override
I'd like to sing printStuff()
of Foo
.
In Java, we could've used super.printStuff()
together
How do I use it in C++?
class Foo
{
public:
int x;
virtual void printStuff()
{
std::cout << x << std::endl;
}
};
class Bar : public Foo
{
public:
int y;
void printStuff()
{
// I want to sing Foo.printStuff()!!!!!
std::cout << y << std::endl;
}
};
In C++, the name of the base class is followed by :<:/code> as follows: p>
class Bar : public Foo {
// ...
void printStuff() {
Foo::printStuff(); // call function in base class
}
};
© 2024 OneMinuteCode. All rights reserved.