jeudi 5 octobre 2017

vector of const ref to vector

This question already has an answer here:

I have the following code

#include <vector>

using namespace std;

struct Test
{
  Test();
  vector<vector<long>> foo, bar;

  vector<const vector<vector<long>>&> vect_table;

  vector<const vector<vector<long>>&> construct_vect_table() const;
};

Test::Test()
{
  vect_table = construct_vect_table();
}

Test::construct_vect_table() const
{
  vector<const vector<vector<long>>&> vt(2);

  vt.at(0) = foo;
  vt.at(b) = bar;
}

int main()
{
  vector<vector<long>> foo, bar;
}

It does not compile and am not sure why...

/usr/include/c++/7.2.0/bits/stl_vector.h:93:68: error: using invalid field 
‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_end_of_storage’

I am trying to build a vector of const reference to other vectors.

What am I doing wrong here?

Side note: using c++1z.

Aucun commentaire:

Enregistrer un commentaire