Every time I run my code. The terminal says "Segment fault". (I'm new to c++ so maybe you could help me improving my code) I have a base class called "Animal" and a "Dog" and a "Cat" class. I wan't to run "doSmth". In the main I created Cat* and Dog* both Pointer. I use CodeBlocks and my Operating System is Ubuntu 16.04.
#include <iostream>
#ifndef ANIMAL_H
#define ANIMAL_H
class Cat;
class Dog;
class Animal
{
public:
Animal();
virtual ~Animal();
virtual void doSmth();
protected:
private:
};
#endif
#ifndef CAT_H
#define CAT_H
class Cat : public Animal
{
public:
Cat();
virtual ~Cat();
void doSmth()
{
std::cout << "Miau" << std::endl;
}
protected:
private:
};
#endif
#ifndef DOG_H
#define DOG_H
class Dog : public Animal
{
public:
Dog();
virtual ~Dog();
void doSmth()
{enter code here
std::cout << "Wuff" << std::endl;
}
protected:
private:
};
#endif
int main()
{
Dog* d;
Cat* c;
d->doSmth();
c->doSmth();
return 0;
}