Avatar ·

How to call a parent class method from an overridden method in C++?

Hello! I'm learning C++ and can't figure out inheritance. I have a base class `Animal` with a virtual method `Speak()` that outputs "Some generic animal sound". I'm creating a derived class `Dog` that overrides this method to output "Woof!". The problem is that in the `Speak()` method of the `Dog` class, I need to first execute the code from the parent class `Animal::Speak()`, and then add my own specific output for the dog. I'm trying to call it directly, but I can't get it to work. Here's my code: ```cpp #include using namespace std; class Animal { public: virtual void Speak() { cout << "Some generic animal sound" << endl; } }; class Dog : public Animal { public: void Speak() override { // Here I want to first