gpt4 book ai didi

c++ - clang 和 g++ 在处理 const 对象时的差异

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:39 24 4
gpt4 key购买 nike

<分区>

考虑代码:

struct Foo
{
int x = 10;
};

int main()
{
const Foo foo;
}

它在 g++ 下编译 http://coliru.stacked-crooked.com/a/99bd8006e10b47ef , 但是在 clang++ http://coliru.stacked-crooked.com/a/93f94f7d9625b579 下会报错:

error: default initialization of an object of const type
'const Foo' requires a user-provided default constructor

我不确定谁在这儿。既然我们执行类内初始化,为什么我们需要一个默认构造函数?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com