It is probably a sily mistake... I started to code using C++ language. I have created an abstract class:
class Animal{
protected:
string name;
int age;
string noise;
string scientific_name;
public:
Animal(){
cout<<"teste"<<endl;
}
virtual void setScientificName();
string getName(){
return name;
}
int getAge(){
return this->age;
}
//virtual int getAge();
string getScientificName(){
return scientific_name;
};
};
Derivated it into to other classes:
class Dog: public Animal{
public:
Dog():Animal(){
setScientificName();
}
void setScientificName() override {
scientific_name = "Canis Lupus Familiaris";
}
};
class Cat: public Animal{
public:
Cat():Animal(){
setScientificName();
}
void setScientificName() override {
scientific_name = "Felis catus";
}
};
Tested it:
int main()
{
Cat c;
cout << "Hello world! " << c.getScientificName() << endl;
system("Pause");
return 0;
}
Even though I have implemented the virtual function, I´ve got the error:
||=== Build: Debug in teste (compiler: GNU GCC Compiler) ===| obj\Debug\main.o||In function
ZN6AnimalC2Ev':| C:\Users\study\Código em C\teste\main.cpp|15|undefined reference to
vtable for Animal'| obj\Debug\main.o||In functionZN6AnimalD2Ev':| C:\Users\study\Código em C\teste\main.cpp|6|undefined reference to
vtable for Animal'| ||error: ld returned 1 exit status| ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
Why?