I am creating a program to practice my knowledge on classes and files but I can get it to work. Previously I was getting an error saying that robots::robots() was defined multiple times but now I have this error saying undefined reference to 'robots::robots()'. Here is the code for enemy_definitions.h:
#include <iostream>
using namespace std;
class enemies
{
public:
string name;
int hp;
int damage;
virtual void print_information();
};
class robots: public enemies
{
public:
robots();
void print_information();
private:
int power_requirement;
};
class zombies: public enemies
{
public:
void print_information();
private:
int height;
};
class aliens: public enemies
{
public:
void print_information();
private:
string colour;
};
Here is the code for enemy_definitions.cpp:
#include <iostream>
#include "enemy_definitions.h"
void enemies :: print_information()
{
}
robots :: robots()
{
cout <<"Name: ";
cin >> name;
cout <<"\nhp: ";
cin >> hp;
cout <<"\ndamage: ";
cin >> damage;
cout <<"\n power_requirement: ";
cin >> power_requirement;
}
void robots :: print_information()
{
cout << this->name << " has ";
cout << this->hp << "hit-points, ";
cout << this->damage << " damage and ";
cout << this->power_requirement << "power requirement";
}
void zombies :: print_information()
{
cout << this->name << " has ";
cout << this->hp << "hit-points, ";
cout << this->damage << " damage and ";
cout << this->height << "height";
}
void aliens :: print_information()
{
cout << this->name << " has ";
cout << this->hp << "hit-points, ";
cout << this->damage << " damage and ";
cout << this->colour << "colour";
}
and here is the code for main.cpp:
#include <iostream>
#include "enemy_definitions.h"
using namespace std;
int main()
{
robots Bertha;
Bertha.print_information();
}
Can someone spot why I keep getting this error.