相关疑难解决方法(0)

没有临时数组的列表初始化-在GCC中不起作用

考虑下面的人为例子

struct A {
    A(int) {}
    A(const A&) = delete;
    ~A() {}
};

struct B {
    A a[2] = {{1}, {2}};
};

int main() {
    B b;
}
Run Code Online (Sandbox Code Playgroud)

它可以在clang(任何版本)中正常编译,但在GCC(任何版本,任何标准> = C ++ 11)中均不能编译

<source>: In constructor 'constexpr B::B()':
<source>:7:8: error: use of deleted function 'A::A(const A&)'
 struct B {
        ^
<source>:3:5: note: declared here
     A(const A&) = delete;
     ^
<source>: In function 'int main()':
<source>:12:7: note: synthesized method 'constexpr B::B()' first required here
     B b; …
Run Code Online (Sandbox Code Playgroud)

c++ gcc language-lawyer c++11

15
推荐指数
1
解决办法
252
查看次数

标签 统计

c++ ×1

c++11 ×1

gcc ×1

language-lawyer ×1