You've got it backwards - public inheritance represents IS-A relationship. So your usage is saying that "every human is a man, and every human is a woman." That doesn't really work. Public inheritance should never be used as just a convenience for "getting all the functionality in one spot." That's what composition (or at worst, non-public inheritance) is for.
Your situation is a great example for employing inheritance, though. It just has to follow its natural definition (every man is a human; every woman is a human). That is, make Human
the base class and implement all shared functionality there. Something like this:
class Human
{
protected:
std::string name;
virtual std::string getGenderString() const = 0;
public:
virtual ~Human() {} //dtor must be virtual to be usable as a polymorphic base class
void getInfo(std::string hName)
{ name = hName; }
void showInfo() const
{
std::cout << "Your name is: " << name << '\n';
std::cout << "And you are a " << getGenderString() << std::endl;
}
};
class Man : public Human
{
protected:
virtual std::string getGenderString() const
{ return "MAN"; }
};
class Woman : public Human
{
protected:
virtual std::string getGenderString() const
{ return "WOMAN"; }
};
int main(){
//local variables
std::string choice;
std::string tName;
//declaring objects
Human *person = NULL;
//user interface
std::cout << "Please enter you name: ";
std::cin >> tName;
std::cout << "Are you a [boy/girl]: ";
std::cin >> choice;
//if handler
if (choice == "boy"){
person = new Man();
}else if(choice == "girl"){
person = new Woman();
}
person->getInfo(tName);
person->showInfo();
system("pause");
delete person;
return 0;
}
The above code uses a pure virtual function (one which has to be implemented in a derived class) to get the appropriate gender string. Everything else is common to both genders, so it's in the base class.
Note that there's a lot of good practice which could be added to the code, but I didn't want to confuse the issue too much. I didn't know if you have access to C++11 features, so I didn't use any. Your best bet for turning the above (working) code into good code is picking up a good C++ book.