PDA

View Full Version : vector iterator as pointer problem


Teerayoot
6th May 2007, 18:00
Hi all

I have a problem about vector

old code i using BCB


std::vector<SkillEffectStatus> vSkillEffectStatus
.
.
.
vSkillEffectStatus.erase(&vSkillEffectStatus[i]);

BCB compile good but

when i try compile using Visual i got small error below

Error 1 error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)' : cannot convert parameter 1 from 'SkillEffectStatus *' to 'std::_Vector_iterator<_Ty,_Alloc>' f:\documents and settings\administrator.if2007\my documents\visual studio 2005\projects\bot_library\bot_library\MyPlayer.h 252



seem compiler not allow to convert iterator to pointer
i already force cast to it but failed.

Thank for your answer in advance.

wysota
6th May 2007, 19:23
vSkillEffectStatus.erase(vSkillEffectStatus.begin( )+i);

Teerayoot
6th May 2007, 19:44
right it work.

But many code accept pointer like this


static void remove(char *NAME){
Friend *ret = find(NAME);
if(ret!=NULL){
vFriend.erase(ret);
}
}
Can i directly convert pointer to iterator?

wysota
6th May 2007, 21:36
But many code accept pointer like this
But erase takes an iterator not a pointer.


static void remove(char *NAME){
Friend *ret = find(NAME);
if(ret!=NULL){
vFriend.erase(ret);
}
}
Depends what vFriend is and what it contains.

Can i directly convert pointer to iterator?
Not in this situation. Especially that you don't have any benefit of using a pointer here.