我的課extPersonType
是從3個其他類繼承。該程序編譯沒有錯誤,但由於某種原因字符串relation
和phoneNumber
不顯示。我要求的所有其他信息的確如此。我的問題在哪裏?爲什麼我在調用print()函數時不會輸出字符串?
class extPersonType: public personType, public dateType, public addressType
{
public:
extPersonType(string relation = "", string phoneNumber = "", string address = "", string city = "", string state = "", int zipCode = 55555, string first = "", string last = "",
int month = 1, int day = 1, int year = 0001)
: addressType(address, city, state, zipCode), personType(first, last), dateType (month, day, year)
{
}
void print() const;
private:
string relation;
string phoneNumber;
};
void extPersonType::print() const
{
cout << "Relationship: " << relation << endl;
cout << "Phone Number: " << phoneNumber << endl;
addressType::print();
personType::print();
dateType::printDate();
}
/*******
MAIN PROGRAM
*******/
int main()
{
extPersonType my_home("Friend", "555-4567", "5142 Wyatt Road", "North Pole", "AK", 99705, "Jesse", "Alford", 5, 24, 1988);
my_home .extPersonType::print();
return 0;
}
正如一邊,使用多繼承可能不是你想如何建模關係 – Leon