1
votes

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.

2
Sorry...I left out the int in the vector declaration: vector< vector< vector < int > > > classVariable_; Same question still applies. :-)bsofman
Is it a good idea to go 3 levels deep? You might want to take another look at your approach to eliminate complexity if it is not absolutely necessaryChris Ballance
bsofman: Oh, OK. I'm out of ideas for now, then. :)bcat
What would be some preferable alternatives? I don't know any of the dimensions ahead of time so I can't just use a multi-dimensional array or boost multi-array.bsofman

2 Answers

4
votes

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.

0
votes

If they are just warnings I don't think it can be anything major, but the warnings are for _result and _cur not being initialized.

Maybe try clearing the lowest level vector and work your way back up?