Fellow ROOTers,
I’m having some problems using iterators for an STL list of vectors. It seems ROOT cannot create an iterator for list<vector >;
I’m running 5.24/00 on RHEL4.
Here is the code:
[code]#include
#include
#include
#include
using namespace std;
class CTest
{
public:
typedef vector VECTORD_t;
CTest(void) {}
virtual ~CTest(void){}
// works
void DoIt0(void) {
list<string> ls;
ls.push_back("This");
ls.push_back("That");
ls.push_back("The Other Thing");
list<string>::iterator it;
it = ls.begin();
while (it != ls.end()) {
cout << (*it) << endl;
it++;
}
}
// does not work
void DoIt1(void) {
VECTORD_t vf0(2); vf0[0] = 1.0; vf0[1] = 2.0;
VECTORD_t vf1(2); vf1[0] = 3.0; vf1[1] = 3.0;
list<VECTORD_t> lv;
lv.push_back(vf0);
lv.push_back(vf1);
list<VECTORD_t>::iterator it;
it = ls.begin();
while (it != ls.end()) {
vector<double> vf = (*it);
for (int i=0; i<vf.size(); i++) {
cout << vf[i] << endl;
}
it++;
}
}
// does not work
void DoIt2(void) {
vector<double> vf0(2); vf0[0] = 1.0; vf0[1] = 2.0;
vector<double> vf1(2); vf1[0] = 3.0; vf1[1] = 3.0;
list<vector<double> > lv;
lv.push_back(vf0);
lv.push_back(vf1);
list<vector<double> >::iterator it;
it = ls.begin();
while (it != ls.end()) {
vector<double> vf = (*it);
for (int i=0; i<vf.size(); i++) {
cout << vf[i] << endl;
}
it++;
}
}
};
#ifdef MAKECINT
#pragma link C++ class std::liststd::string;
#pragma link C++ class std::vector;
#pragma link C++ class std::list<std::vector >;
#pragma link C++ class std::list<std::vector >::iterator;
#pragma linkc C++ typedef CTest::VECTORD_t;
#pragma link C++ class std::listCTest::VECTORD_t;
#pragma link C++ class std::listCTest::VECTORD_t::iterator;
#endif
[/code]
Here is the error message:
[code]root [0] .L verysimpletest.C
.L verysimpletest.C
root [1] CTest* t = new CTest
CTest* t = new CTest
root [2] t->DoIt1()
t->DoIt1()
Error: can not call private or protected function _list.h:300:
_list.h 138 list<vector<double,allocator > >::iterator list<vector<double,allocator > >::iterator::iterator(list<vector<double,allocator > >::link_type);
Calling : list<vector<double,allocator > >::iterator::iterator(long);
Match rank: file line signature
1000000 _list.h 143 list<vector<double,allocator > >::iterator list<vector<double,allocator > >::iterator::iterator(list<vector<double,allocator > >::iterator&);
ffffffff _list.h 140 list<vector<double,allocator > >::iterator list<vector<double,allocator > >::iterator::iterator();
- 10002 _list.h 138 list<vector<double,allocator > >::iterator list<vector<double,allocator > >::iterator::iterator(list<vector<double,allocator > >::link_type);
*** Interpreter error recovered ***
root [3] .q
[/code]
Any help is appreciated.
Thanks,
Terry[/code]