18 lines
432 B
C++
18 lines
432 B
C++
#include "animal.h"
|
|
#include "cat.h"
|
|
#include "dog.h"
|
|
|
|
#include <string>
|
|
|
|
int main() {
|
|
// because cat and dog are subclasses of animal, they can be stored in an array of animals
|
|
animal * animals[2] = {
|
|
new dog("buster"),
|
|
new cat("mittens")
|
|
};
|
|
|
|
for (animal * a : animals)
|
|
// when calling the make_sound function, the implementation of the actual class gets called (in this case cat or dog)
|
|
a->make_sound();
|
|
}
|