Compiler & Runtime Binding
class Animal {
public:
void Sound() {
cout << "Generic animal sound" << endl;
}
};
class Dog : public Animal {
public:
void Sound() {
cout << "Woof! Woof!" << endl;
}
};
int main() {
Animal* myAnimal = new Dog();
myAnimal->Sound(); // Calls Animal::Sound() at compile time, not Dog::Sound().
delete myAnimal;
return 0;
}Last updated