Vectors of vectors in the ROOT interpreter

I am running into problems trying to use std::vector to make two-dimensional arrays in the ROOT interpreter. Why does the following not work from the ROOT prompt?

#include <vector>
std::vector<std::vector<double> > x;

I get an error message, saying
Error: illegal type cast (2) FILE:_vector.h LINE:170
*** Interpreter error recovered ***

Neither does

std::vector<std::vector<double> > x(2);

work, giving a similar error message
Error: illegal type cast (2) FILE:_vector.h LINE:78
*** Interpreter error recovered ***

Any other suggestion for using two-dimensional vectors, or some equivalent would be welcome. I am using ROOT 3.10.02 on a Linux x86 machine.



For most non-trivial use of stl container, it is recommended to use compiled code. And it is necessary to do so, if you are going to pass those stl containers to some of your compiled code.

For example, you could create a simple file ‘vectorDict.C’:

#include <vector> #ifdef __CINT__ #pragma link C++ class vector<vector<double> >; #endif then do.L vectorDict.C+
Sorrowfully, resize still won’t work but you can create another small file (or you can merge into vectorDict.C): ‘quick.C’

#include <vector> resize(std::vector<std::vector<double> >&vec,int n) { vec.resize(n); }
and then

root [0].L vectorDict.C+ root [1].L quick.C+ root [2] vector<vector<double> > v root [2] resize(v,3) root [3] v.size() (const unsigned int)3