struct foo
{
struct bar {
~bar() {} // no error w/o this line
};
bar *data = nullptr; // no error w/o this line
foo() noexcept = default; // no error w/o this line
};
是的,我知道,有一个与正是另一个问题标题相同,但结构稍有不同的问题(涉及noexcept
操作并没有嵌套的类型)。该解决方案建议有(与“在成员函数外部封装类的定义中需要的默认成员初始值设定项” - 是我的代码格式不正确吗?
foo() noexcept {}
更换的foo
构造函数)改变语义,它没有必要在这里:我们这里有一个更好的答案(因此这个问题不是一个重复)。
编译:Apple LLVM version 9.0.0 (clang-900.0.37)
,完整的错误信息:
test.cc:44:5: error: default member initializer for 'data' needed within definition of enclosing class 'foo' outside of member functions
foo() noexcept = default;
^
test.cc:41:10: note: default member initializer declared here
bar* data = nullptr;
^
你可以只declarare析构函数在'bar'和将其定义在课堂外。这种方式编译。 – skypjack
这是一个铿锵虫。 – Oliv
[“在成员函数外部封装类的定义中需要的默认成员初始值设定项”的可能重复项是否是我的代码格式不正确?](https://stackoverflow.com/questions/43819314/default-member-initializer-needed- within-definition-of-enclosing-class-outside) –