Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
#include
using namespace std; class Animal { public: void animalSound() { cout << "The animal makes a sound\n"; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow\n"; } }; int main() { Dog myDog; Animal* a = &myDog; // A pointer to the base class (Animal), pointing to a Dog a->animalSound(); // animalSound() is not virtual, so this calls Animal's version return 0; }
The animal makes a sound