【发布时间】:2016-05-10 23:01:21
【问题描述】:
正如我们在 c++ 中所知道的,我们可以重新初始化一个大小为 N 且值为 0 的数组 arr,
fill (arr, arr + N, 0);
但我需要使用struct S 重新初始化数组,
struct S {
int b[2];
}
实际代码是,
#include <iostream>
using namespace std;
struct Dog
{
int count[2];
};
int main(){
...
Dog dogs[N];
...
while (T--)
{
...
for (int i = 0; i < M; ++i)
{
fill(dogs, dogs+N, {0});
...
}
...
}
}
【问题讨论】:
-
您遇到
std::fill的问题了吗? -
同样使用
fill -
@M.M @juanchopanza 使用类似填充,
fill (arr, arr+N, {0})引发数组。我知道语法没有意义,我是否必须创建一个临时结构变量来初始化? -
我认为语法实际上可能是有效的。是的,它需要一个临时结构,但
{0}可能会这样做。 -
@MooingDuck 它给出了一个错误
/usr/include/c++/4.8/bits/stl_algobase.h:721:5: note: template argument deduction/substitution failed: