【发布时间】:2013-08-09 18:31:58
【问题描述】:
int a[10];
int b[10];
a = b;
//
struct test {
int a[10];
};
test a,b;
a = b;
第一个代码无法编译,因为我们不能分配数组,但第二个代码可以。类的默认赋值运算符不是简单地为每个数据成员调用赋值吗?为什么第二段代码会编译?
【问题讨论】:
-
默认的类赋值运算符将复制数组的所有元素。这就是
std::array在没有用户提供的情况下的工作方式。 -
因为作为成员的数组有一个特殊的例外。
-
为什么涉及std::array?我错过了什么吗?
标签: c++ compiler-errors variable-assignment assignment-operator