这是我的代码:
class Foo
{
public:
Foo(const char*);
};
class Bar
{
public:
Foo bu("adfds");
};
int main()
{
return 0;
}
Foo::Foo(const char* iLoc)
{ }
当我尝试在 Bar
类中创建一个 Foo
类时,我在尝试传递给构造函数时遇到语法错误。为什么会这样?
最佳答案
我更喜欢这个而不是 egrunin 的答案,因为您不必跟踪内存分配。
class Bar
{
private:
Foo bu;
public:
Bar()
: bu("adfds")
{
}
};
关于c++ - 我该如何解决错误 C2059 : syntax error : 'string' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9123672/