给定以下代码片段:
class Foo {};
Foo makeFoo() { return Foo{}; }
int main()
{
Foo myFoo{makeFoo()};
}
我希望单行main
声明和定义/初始化myFoo
使用Foo
的移动构造函数的返回值makeFoo()
。
clang++
但是,我从3.5.1(以 C++14 模式编译)收到以下错误:
error: excess elements in struct initializer
Foo myFoo{makeFoo()};
^~~~~~~~~
1 error generated.
这里发生了什么?“结构初始化程序”到底是什么意思——它只是 POD 的默认(无参数)构造函数吗?为什么不调用移动构造函数?