Results 1 to 4 of 4

Thread: vector iterator as pointer problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    44
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default vector iterator as pointer problem

    Hi all

    I have a problem about vector

    old code i using BCB

    Qt Code:
    1. std::vector<SkillEffectStatus> vSkillEffectStatus
    2. .
    3. .
    4. .
    5. vSkillEffectStatus.erase(&vSkillEffectStatus[i]);
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by jacek; 9th May 2007 at 00:10. Reason: changed [code] to [quote]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: vector iterator as pointer problem

    Qt Code:
    1. vSkillEffectStatus.erase(vSkillEffectStatus.begin()+i);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2007
    Posts
    44
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default Re: vector iterator as pointer problem

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: vector iterator as pointer problem

    Quote Originally Posted by Teerayoot View Post
    But many code accept pointer like this
    But erase takes an iterator not a pointer.


    Qt Code:
    1. static void remove(char *NAME){
    2. Friend *ret = find(NAME);
    3. if(ret!=NULL){
    4. vFriend.erase(ret);
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  2. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  3. Signals destroys my pointer
    By Jojo in forum Qt Programming
    Replies: 12
    Last Post: 7th March 2006, 21:05
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.