Wow! It's been a LONG time since coding but am just getting back to it and have lost SOOO much knowledge. I just have a question about classes...more specifically inheritance I think. Say for instance I have 2 classes. One called playerClass and one called getInfoClass. My problem lies in getting the two classes to talk to one another. I gather info from the user in the getInfoClass and need to set a lot of variables in the playerClass from the values entered using functions inside the getInfoClass. I cannot remember but would you use inheritance to get the classes to talk to one another??? Here is a snippet of some of the code.
class playerClass
{
public:
playerClass();
void setName(string);
void setAge(string);
void setGender(string);
void setBodyType(string);
void printName();
private:
///The value of these 4 variables below will come from the getInfoClass
string name;
string age;
string gender;
string bodyType;
};
class getInfoClass
{
public:
getInfoClass();
void errorCheckAge(int&);
void getPlayerInfo();
void errorCheckInfo(string&, vector<string>);
void capitalizeFirstLetters(string&);
private:
int age;
string name;
string gender;
string bodyType;
bool isThereError;
vector<string>genderVector;
vector<string>bodyTypeVector;
};
///HERE IS THE DEFINTION OF GETTING THE INFO. AFTER A VALUE IS ENTERED I WANT
///TO SET THE VALUE RIGHT IN THIS CLASS DEFINTION
void getInfoClass::getPlayerInfo()
{
cout<<"What is your name? ";
getline(cin, name);
capitalizeFirstLetters(name);
cout<<endl;
cout<<"What is your age?\nEnter between 13 and 99: ";
cin>>age;
errorCheckAge(age);
cout<<endl;
cout<<"What is your gender?\nEnter male of female: ";
cin>>gender;
errorCheckInfo(gender, genderVector);
cout<<endl;
cout<<"What is your body type?\nEnter small, average, or massive: ";
cin>>bodyType;
errorCheckInfo(bodyType, bodyTypeVector);
cout<<endl;
}
Time to dust off my book......thanks for any replies!
class playerClass
{
public:
playerClass();
void setName(string);
void setAge(string);
void setGender(string);
void setBodyType(string);
void printName();
private: //could be public depending on how you would like to use getInfoClass
getInfoClass Info; //must initialise Info in the constructor if private
};
class getInfoClass
{ friendclass playerClass;
public:
getInfoClass();
void errorCheckAge(int&);
void getPlayerInfo();
void errorCheckInfo(string&, vector<string>);
void capitalizeFirstLetters(string&);
private:
int age;
string name;
string gender;
string bodyType;
bool isThereError;
vector<string>genderVector;
vector<string>bodyTypeVector;
};