-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