【发布时间】:2017-04-25 22:54:53
【问题描述】:
请有人帮我纠正以下问题。我正试图围绕如何在新对象中创建指向现有对象的指针。我无法让语法正确并不断出错。
这是我的代码:
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; -
您缺少 person 变量的名称,以及声明后的分号 - 除此之外,您在寻找什么?