The following code gives me an error.
Error: overriding 'virtual void Animal::getClass()', where it says virtual void getClass() { cout << "I'm an animal" << endl; }
Error: conflicting return type specified for 'virtual int Dog::getClass()', where it says getClass(){ cout << "I'm a dog" << endl; }
Also, it says:
Class 'Dog' has virtual method 'getClass' but non-virtual destructor
#include
#include
#include
#include
#include
#include // srand, rand
#include
using namespace std;
class Animal{
public:
void getFamily(){ cout << "We are animals " << endl;}
virtual void getClass() { cout << "I'm an animal" << endl; }
};
class Dog : public Animal{
public:
getClass(){ cout << "I'm a dog" << endl; }
};
void whatClassAreYou(Animal *animal){
animal -> getClass();
}
int main(){
Animal *animal = new Animal;
Dog *dog = new Dog;
animal->getClass();
dog->getClass();
whatClassAreYou(animal);
whatClassAreYou(dog);
return 0;
}
No comments:
Post a Comment