I Can T Figure Out Why The Use Of Virtual In The C Code Below Does Not Solve My
I can’t figure out why the use of Virtual in the C++ code below does not solve my problem of multiple inheritance:
#include <iostream>
using namespace std;
class LivingThing {
public:
void breathe() {
std::cout << “I’m breathing as a living thing.” << std::endl;
}
};
class Animal : virtual public LivingThing {
public:
void breathe() {
std::cout << “I’m breathing as an animal.” << std::endl;
}
};
class Reptile : virtual public LivingThing {
public:
void breathe() {
std::cout << “I’m breathing as a reptile.” << std::endl;
}
void crawl() {
std::cout << “I’m crawling as a reptile.” << std::endl;
}
};
class Snake : public Animal, public Reptile {
};
int main() {
Snake snake;
snake.breathe();
snake.crawl();
return 0;
}
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
