-1
可能有人請幫我糾正下面的問題。我試圖圍繞如何創建一個指向新對象內現有對象的指針。我無法獲得正確的語法並不斷收到錯誤。在一個類中創建一個指針到另一個對象
這裏是我的代碼:
class Country
{
string name;
public:
Country (string name)
{ name = name;
cout << "Country has been created" << endl;}
~Country()
{cout << "Country destroyed \n";}
};
class Person
{
//string name;
//Date dateOfBirth;
Country *pCountry;
public:
Person(Country *c):
pCountry(c)
{}
};
int main()
{
Country US("United States");
Person(&US)
return 0;
}
你能編輯帖子以包括你得到的錯誤嗎? –
停下來,深呼吸一下,想一想這個外表多麼愚蠢.'name = name;' – user4581301
你錯過了你的person變量的名字,並且在它的聲明後面有一個分號 - 除此之外,你在找什麼? – jdunlop