I can’t figure out why the use of Virtual in the C++ code below does not solve my problem of multiple inheritance:
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 {
Need assignment help for this question?
If you need assistance with writing your essay, we are ready to help you!
OUR PROCESS
Order
Payment
Writing
Delivery
Why Choose Us: Cost-efficiency, Plagiarism free, Money Back Guarantee, On-time Delivery, Total Сonfidentiality, 24/7 Support, 100% originality
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;
}