简体   繁体   English

std :: vector中没有名为iterator_category的类型

[英]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.

相关问题 遇到错误:“struct std::iterator_traits”中没有名为“iterator_category”的类型<std::vector<int> &gt; - Encountring error: no type named ‘iterator_category’ in ‘struct std::iterator_traits<std::vector<int> > “struct std::iterator_traits”中没有名为“iterator_category”的类型<int* const> '</int*> - No type named 'iterator_category' in 'struct std::iterator_traits<int* const>' 铛错误:c ++ / 4.8 / bits / stl_iterator_base_types.h:227:29:错误:&#39;std :: iterator_traits中没有名为&#39;iterator_category&#39;的类型 <unsigned long> “ - clang error: c++/4.8/bits/stl_iterator_base_types.h:227:29: error: no type named 'iterator_category' in 'std::iterator_traits<unsigned long>' std::iterator_traits 中的 iterator_category 与 iterator_category() 有什么区别 - What is a difference between iterator_category vs iterator_category() in std::iterator_traits iterator_category和decltype - iterator_category and decltype iterator_category&#39;:不是&#39;std :: iterator_traits &lt;_InIt&gt;&#39;的任何基类的成员 - iterator_category': is not a member of any base class of 'std::iterator_traits<_InIt>' C++ 部分模板特化:如何特化 std::iterator_category - C++ partial template specialization: how to specialize std::iterator_category 如何使用 iterator_category 表示自定义迭代器 class 的标签? - How to use iterator_category to indicate the tag of a customized iterator class? 定义transform_view ::iterator的iterator_category的问题? - The problem of the definition of transform_view​::iterator's iterator_category? STL算法找不到iterator_category() - STL algorithm doesn't find iterator_category( )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM