I have an error (vector iterator incompatibles) during execution in my C++ program that I do not understand. [ (Windows / Visual C++ 2008 Express) ]
Here is a simplified version of my problem :
#include <vector>
class A
{
int mySuperInt;
public:
A(int val) : mySuperInt(val) {}
};
class B
{
std::vector<A*> myAs;
public:
B()
{
myAs.push_back(new A(1));
};
const std::vector<A*> getA() const {return myAs;}
};
int main()
{
std::vector<B>* myBs = new std::vector<B>;
myBs->push_back(B());
std::vector<B>::const_iterator it_B = myBs->begin();
for ( ; it_B != myBs->end(); ++it_B)
{
std::vector<A*>::const_iterator it_A = it_B->getA().begin();
for ( ; it_A != it_B->getA().end(); ++it_A) // <-- Error during execution: vector iterator incompatibles
{
// Do stuff
// ...
}
}
}
Did I missed something ?
Thanks in advance for your answers.