构造函数中的引用初始化

时间:2015-10-08 04:18:51

标签: c++ constructor reference

考虑C ++标准12.6.2 / 11中的以下片段:

struct A {
    A() = default; // OK
    A(int v) : v(v) { } // OK
    const int& v = 42; // OK
};
A a1; // error: ill-formed binding of temporary to reference
A a2(1); // OK, unfortunately

他们为什么说A a2(1);不好?有什么问题?

0 个答案:

没有答案