gpt4 book ai didi

c++ - 将 braced-init-list 分配给数组是否正确?

转载 作者:可可西里 更新时间:2023-11-01 16:41:39 27 4
gpt4 key购买 nike

<分区>

标准说,5.17/9下

A braced-init-list may appear on the right-hand side of
- an assignment to a scalar [...]
- an assignment defined by a user-defined assignment operator [..]

在 GCC 4.5.1-pre9999 中,我可以编译它(使用 -std=c++0x,而不是 -std=gnu++0x)

#include <iostream>

int main()
{
int test[] = {1,2,3};
std::cout << test[0] << test[1] << test[2];
test = {4,5,6};
std::cout << test[0] << test[1] << test[2] << std::endl;
}

并打印 123456。 GCC 在这里是正确的吗?

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