Hey guys i am having trouble with creating a Parent class(gameobject) for two other child classes(player,location) both of the child classes can access data from the parent class, and work well independently but once i include the h file for the child classes together in main.cpp i get the compiler error stating base class unidentified and class type redefinition is visual c++ what am i doing wrong ? sorry for the formating
//BASE CLASS OR PARENT CLASS
#include <iostream>
#include <string>
using namespace std;
class GameObject
{
public :
string gamename;
string gametype;
string gamesize;
//default constructor
GameObject()
{
gamename = " Beta ";
gametype = " Not defined ";
gamesize = " Not defined ";
}
//primary constructor
GameObject(string name,string type,string size)
{
gamename = name;
gametype = type;
gamesize = size;
}
//copy constructor
GameObject(GameObject &obj)
{
gamename = obj.gamename;
gametype = obj.gametype;
gamesize = obj.gamesize;
}
// Input Data
void GetGame()
{
cout << " Enter Game Name : ";
getline(cin,gamename);
cout << " Enter Game Type : ";
getline(cin,gametype);
cout << " Enter Game Size : ";
getline(cin,gamesize);
cout << "\n\n";
}
// Print Data
void PrintGame()
{
cout << " Game Name : " << gamename << endl;
cout << " Game Type : " << gametype << endl;
cout << " Game Size : " << gamesize << endl;
cout << "\n\n";
}
}; // END OF CLASS
// CHILD CLASS TO PARENT CLASS GAMEOBJECT
#include <iostream>
#include <string>
#include "GameObject.h"
using namespace std;
class Player : public GameObject
{
public:
string playername;
string playerrole;
string playerstrength;
//Default Constructor
Player()
{
playername = " ";
playerrole = " ";
playerstrength = " ";
}
//Primary Constructor
Player(string pname,string prole,string pstren)
{
playername = pname;
playerrole = prole;
playerstrength = pstren;
}
//Copy Constructor
Player(Player &obj)
{
playername = obj.playername;
playerrole = obj.playerrole;
playerstrength = obj.playerstrength;
}
//Player Input
void GetPlayer()
{
cout << " Enter Player Name : ";
getline(cin,playername);
cout << " Enter Player Role : ";
getline(cin,playerrole);
cout << " Enter Player Strength : ";
getline(cin,playerstrength);
cout << "\n\n";
}
void PrintPlayer()
{
cout << " Player Name : " << playername << endl;
cout << " Player Role : " << playerrole << endl;
cout << " Player Strength : " << playerstrength << endl;
cout << "\n\n";
}
};// END OF CLASS
// Child Class 2 to Parent Class GameObject
#include <iostream>
#include <string>
#include "GameObject.h"
using namespace std;
class Location : public GameObject
{
public:
string locationname;
string climate;
string terrain;
Location()
{
locationname = " ";
climate = " ";
terrain = " ";
}
//Primary Constructor
Location(string locname,string climate_c,string terrain_c)
{
locationname = locname;
climate = climate_c;
terrain = terrain_c;
}
//Copy Constructor
Location(Location &obj)
{
locationname = obj.locationname;
climate = obj.climate;
terrain = obj.terrain;
}
//Get Location Data
void GetLocation()
{
cout << " Location : ";
getline(cin,locationname);
cout << " Climate : ";
getline(cin,climate);
cout << " Terrain : ";
getline(cin,terrain);
}
//Print Location Data
void PrintLocation()
{
cout << " Location : " << locationname << endl;
cout << " Climate : " << climate << endl;
cout << " Terrain : " << terrain << endl;
cout << "\n\n";
}
};//END OF CLASS
//Main.cpp
#include <iostream>
#include <string>
#include "Player.h"
//#include "Location.h"
using namespace std;
void main()
{
Player playa1;
// Location kgn;
playa1.GetGame();
playa1.GetPlayer();
// kgn.GetLocation();
playa1.PrintGame();
playa1.PrintPlayer();
// kgn.PrintLocation();
system("pause");
}