I have two classes, the first that contains a vector and a get-method like this:
std::vector<mytype> const& MyClassA::getvector(std::vector<mytype>::iterator &it)
{
it = this->myiterator;
return this->myvector;
}
std::vector<mytype> myvector;
std::vector<mytype>::iterator myiterator;
and I have another class where I should use the vector:
MyClassB::myfunction()
{
std::vector<mytype>::iterator it;
std::vector<mytype> vector = MyClassA->getvector(it);
if (it > vector.begin())
{
....
(--it)->dosomestuff();
....
}
}
in the if I get a runtime exception: iterators incompatible. Why?
EDIT 1
void MyClassA::setvector(mytype myelement)
{
this->myvector.push_back(myelement);
this->myiterator = this->myvector.end() - 1;
}