|
|
@ -4,7 +4,7 @@
|
|
|
|
class Animal {
|
|
|
|
class Animal {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// Note: using *virtual* does the difference here!
|
|
|
|
// Note: using *virtual* does the difference here!
|
|
|
|
virtual void makeSound() {
|
|
|
|
virtual void makeSound() const {
|
|
|
|
std::cout << "<generic animal sound> from " << this << std::endl;
|
|
|
|
std::cout << "<generic animal sound> from " << this << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -18,14 +18,14 @@ class Animal {
|
|
|
|
|
|
|
|
|
|
|
|
class Cow : public Animal {
|
|
|
|
class Cow : public Animal {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
void makeSound() {
|
|
|
|
void makeSound() const {
|
|
|
|
std::cout << "Mooh. from " << this << std::endl;
|
|
|
|
std::cout << "Mooh. from " << this << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Cat : public Animal {
|
|
|
|
class Cat : public Animal {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
void makeSound() {
|
|
|
|
void makeSound() const {
|
|
|
|
std::cout << "Meow? from " << this << std::endl;
|
|
|
|
std::cout << "Meow? from " << this << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|