Hi
I have just started using STL vectors and iterators so please excuse my ignorance. Suppose I have three classes A,B and C such that :
std::vector<A> aObjects
wherein each object "a" comprises a vector of "b" objects which in turn comprises a vector of "c" objects
ie.
class A{
...
std::vector<B> bObjects;
};
class B{
...
std::vector<C> cObjects;
};
class C{
...
float left,right;
};
I would like to assign an iterator to access the elements(objects) in the arrays aObjects,bObjects and cObjects when initialising the arrays: let's call these aIterator,bIterator,cIterator respectively, i.e.
std::vector<A>::iterator aIterator;
std::vector<B>::iterator bIterator;
std::vector<C>::iterator cIterator
.
I then create each instance of the respective object using
aObject.push_back(A constructor);
What is the best way to initialise the necessary bIterator and cIterator? In the constructor for A and B respectively
A::A{
// add all B objects to vector bObjects
bObjects.push_back(B());
// when finished adding B objects to bObject initialise bIterator
std::vector<B>:iterator =bObjects.begin();
}
How do I then dereference? e.g
aIterator->bIterator->cIterator->left
The alternative is to index the explicit elements i.e.
aObject[i].bObject[j].cObject[k].left
or similar
Thanks in advance
Mark