我试图调用默认拷贝构造函数与统一初始化,但它不工作。调用拷贝构造函数与统一初始化
例如:
#include <string>
struct Work {
std::string author;
std::string name;
int year;
};
int main() {
Work s9 {"Beethoven", "Symphony No. 9 in D minor, Op. 125; Choral", 1824}; // memberwise initialization
Work currently_playing {s9}; // copy initialization
return 0;
}
林编译它:g++ -std=c++11 -c Ex1.cpp
而且编译器会发出错误:
Ex1.cpp: In function ‘int main()’:
Ex1.cpp:11:28: error: could not convert ‘s9’ from ‘Work’ to ‘std::string {aka std::basic_string<char>}’
Work currently_playing {s9}; // copy initialization
^
不统一的初始化工作,以复制初始化对象?
嗯,谢谢。我认为是这样,因为它在msvc中有效。 – UDPLover