使用深度为3或更大的嵌套向量进行编译器警告(Compiler warning with nested vectors of depth 3 or more)

编程入门 行业动态 更新时间:2024-10-27 08:29:22
使用深度为3或更大的嵌套向量进行编译器警告(Compiler warning with nested vectors of depth 3 or more)

我试图使用一个使用深度为3的嵌套向量的类成员:

vector <vector <vector>> classVariable_;

但是,当我尝试执行像classVariable_.clear()这样简单的操作时,我会在整个代码中收到编译器警告:

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:在成员函数`std :: vector <_Tp,_Alloc>&std :: vector <_Tp,_Alloc> :: operator =(const std :: vector <_Tp,_Alloc>&)[with _Tp = std :: vector>,_ Alloc = std :: allocator >>]':/ usr / lib / gcc / i686-pc-cygwin /3.4.4/include/c++/bits/stl_vector.h:715:警告:'__result'可能在此函数中未初始化使用/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/ bits / stl_uninitialized.h:82:警告:'__cur'可能在此函数中未初始化使用/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_uninitialized.h:82:警告:'__cur'可能在此函数中未初始化使用

奇怪的是,这适用于深度为2的嵌套向量,但深度为3或更高。 这与stl库中缺少默认运算符/构造函数有关吗?

有谁知道围绕这个干净的解决方案? 我正在使用cygwin编译它,但这不会对此产生影响。

谢谢。

I am trying to use a class member that uses nested vectors of depth 3:

vector< vector< vector > > classVariable_;

However, I then get compiler warnings throughout my code when I try do something as simple as classVariable_.clear():

/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h: In member function `std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector >, _Alloc = std::allocator > >]': /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_vector.h:715: warning: '__result' might be used uninitialized in this function /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_uninitialized.h:82: warning: '__cur' might be used uninitialized in this function /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_uninitialized.h:82: warning: '__cur' might be used uninitialized in this function

The strange thing is that this works with nested vectors of depth 2, but not of depth 3 or more. Is this something to do with missing default operators/constructors in the stl libraries?

Does anyone know a clean solution around this? I am compiling this using cygwin but that should not have an effect on this.

Thank you.

最满意答案

如果你实际上是指vector< vector< vector< int> > > classVariable_ ,那么classVariable_.clear()不应该产生任何警告。 可能是这个bug 。

手动禁用警告,或避免深度为3的嵌套向量,这可能不是一个好主意。

If you actually mean vector< vector< vector< int> > > classVariable_, then classVariable_.clear() shouldn't produce any warning. Might be this bug.

Disable the warning manually, or avoid nested vectors of depth 3, which might not be a good idea anyway.

更多推荐

本文发布于:2023-08-08 01:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   嵌套   更大   编译器   深度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!