Is it possible to save a pointer to an object in a vector inside a loop?
For example:
rpc::session* session=NULL;
//Find Sessions with same UserID, Remove if > 1
for(std::vector<rpc::session>::iterator it = session_manager::sessions.begin(); it != session_manager::sessions.end();) {
if(it->userid == userid){
if(session == NULL) {
*session = *it;
++it;
} else {
it = session_manager::sessions.erase(it);
}
} else {
++it;
}
}
The code gets compiled but as soon as it reaches *session = *it, it crashes with a Access violation..