[英]No type named iterator_category in std::vector
This code is giving an error : 这段代码给出了一个错误:
vector<vector<bool> > revealed(vector<bool>(10, false), vector<bool>(10,false));
I am trying to define a 2D boolean array that has all elements as false by default. 我试图定义一个二维布尔数组,默认情况下所有元素都为false。
The error is 错误是
.\stl_iterator_base_types.h|165|error: no type named 'iterator_category' in 'class std::vector<bool>'|
The error refers to line 165 of stl_iterator_base_types.h 该错误指向stl_iterator_base_types.h的 第165 行
162 template<typename _Iterator>
163 struct iterator_traits
164 {
165 typedef typename _Iterator::iterator_category iterator_category;
166 typedef typename _Iterator::value_type value_type;
167 typedef typename _Iterator::difference_type difference_type;
168 typedef typename _Iterator::pointer pointer;
169 typedef typename _Iterator::reference reference;
170 };
By the way, I am using Code::Blocks(with MinGW) as my IDE 顺便说一句,我使用Code :: Blocks(with MinGW)作为我的IDE
You would initialize such a vector as follows 您可以按如下方式初始化这样的向量
std::vector<std::vector<bool>> revealed(10, std::vector<bool>(10, false));
The reason is that the constructor overload you are trying to use for std::vector
is 原因是您尝试用于
std::vector
的构造函数重载为
vector(size_type count, const T& value);
So you can see the first argument is the count, the second is the value. 因此,您可以看到第一个参数是计数,第二个参数是值。 By this notion, you want the outer vector to be
根据这个概念,您希望外部向量为
vector(10, "vectors_of_length_10_wlth_all_false_values")
^
The way you signify the second argument is 您表示第二个参数的方式是
std::vector<bool>(10, false)
The first argument for the outer vector is simply 10
because you want it to contain 10 of these vectors that have 10 false
values. 外部向量的第一个参数仅为
10
因为您希望它包含10个具有10个false
值的向量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.