Vector<vector<int> > *test problem

Hello,

I have had problems with 2D vectors before, but I can’t seem to get this code running.

I have a tree that contains a vector<vector > * variable and I try to access it as follows in a .C script:

[code]vector<vector > *mc_child_index;
t_in->SetBranchAddress(“mc_child_index”, &mc_child_index);

cout << (mc_child_index->at(0)).at(0) << endl;
[/code]

However I get the error:

Error: Can’t call vector<vector<int,allocator >,allocator<vector<int,allocator > > >::at(0) in current scope MakeEventShapes.C:829:
Possible candidates are…
(in vector<vector<int,allocator >,allocator<vector<int,allocator > > >)
Error: non class,struct,union object $(mc_child_index->at(0)) used with . or -> MakeEventShapes.C:829:
(class G__CINT_ENDL)342510752
*** Interpreter error recovered ***

I have tried

if (!(gInterpreter->IsLoaded("vector"))){ gInterpreter->ProcessLine("#include <vector>"); gSystem->Exec("rm -f AutoDict*vector*vector*int*"); gInterpreter->GenerateDictionary("vector<vector<int> >", "vector"); }

with Loader.C as:

#include<vector> #ifdef __CINT__ #pragma link C++ class vector<vector<int> >; #else template class std::vector<std::vector<int> >; #endif

Currently using 5.34.05 x86_64

Anyone know why this isn’t working? Thanks,

-Julian

Try:
std::vector<std::vector > *mc_child_index = 0; // the pointer MUST be initialized
// …
if (mc_child_index) std::cout << (mc_child_index->at(0)).at(0) << std::endl;
else std::cout << “mc_child_index = 0” << std::endl;

Tried it, I get the same error:

Error: Can’t call vector<vector<int,allocator >,allocator<vector<int,allocator > > >::at(0) in current scope MakeEventShapes.C:830:
Possible candidates are…
(in vector<vector<int,allocator >,allocator<vector<int,allocator > > >)
Error: non class,struct,union object $(mc_child_index->at(0)) used with . or -> MakeEventShapes.C:830:
(class G__CINT_ENDL)64216224
*** Interpreter error recovered ***

Try this example (simply replace all occurrences of “float” with “int”): [url]Storing 2D vector [--> vector<vector<...> >] into a TTree

Ugh, I had some AutoDict_vector_vector_int files in my directory, I deleted them and it now works…

Now I have new ones, not sure why the old ones didn’t work…

Thanks for responding though!

-Julian

Hello,
Sorry to bring up this subject again but I had the same problem and I tried all the solutions here, none of them worked.
I have to read a branch vector<vector >* from a tree. The class to read the tree is generated from MakeSelector. But when running the script I got this error:

Error: Can’t call vector<vector<int,allocator >,allocator<vector<int,allocator > > >
::vector<vector<int,allocator >,allocator<vector<int,allocator > > >() in current sc
ope go.C:14:
Possible candidates are…
(in vector<vector<int,allocator >,allocator<vector<int,allocator > > >)

Could you provide some suggestion how to fix this?

Thanks,
Tran