Skip to main content
gamedev.net
🔒 Locked

Odd Errors

Started by XoreDevelopment 6 replies 550+ views
Original Post
XoreDevelopment
XoreDevelopment
Here is my Error:
Quote:
.\D3DGUI.cpp(160) : error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)' : cannot convert parameter 1 from 'CForm **' to 'std::_Vector_iterator<_Ty,_Alloc>' with [ _Ty=CForm *, _Alloc=std::allocator<CForm *> ] No constructor could take the source type, or constructor overload resolution was ambiguous
Here is what I'm using for the code:
Quote:
m_vFormList.erase(&m_vFormList);
And here is the definition of erase
Quote:
iterator erase(iterator _Where) { // erase element at where _STDEXT unchecked_copy(_VEC_ITER_BASE(_Where) + 1, _Mylast, _VEC_ITER_BASE(_Where)); _Destroy(_Mylast - 1, _Mylast); --_Mylast; return (_Where); }
notice, thats defined in vectors.h! and here is my m_vFormList
Quote:
std::vector<CForm*> m_vFormList;
and here is my CForm class:
Quote:
class CForm { public: CForm(){} ~CForm(){} //pure methods virtual void Initialize() = 0; //accessors virtual const rect_s &GetRect() const; virtual const bool IsSelected(CFormObject *pObject) const; //methods virtual void Render(BYTE alpha); virtual void Move(int offsetx, int offsety); virtual void MouseClick(int mousex, int mousey, bool isDoubleClick = false); virtual void InputCharacter(char c); virtual CFormObject *AddControl(CFormObject *pObject); protected: std::vector<CFormObject*> m_vObjectList; rect_s m_Rect; char m_szTitle[TITLEBAR_LENGTH+1]; CFormObject *m_pSelected; };
Does anyone here know why I am getting this error? This is being used in my D3D Project (if you were wondering how this related to D3D).
matthughson
matthughson
I think the problem is you are passing one of your objects stored in the vector rather than an iterator.

Matt
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Mushu
Mushu
Quote:
Original post by matthughson
I think the problem is you are passing one of your objects stored in the vector rather than an iterator.

Matt

Well yes, but how do you create an iterator without using std::find, which is both slower than random access, and isn't guarenteed to retrieve the value you want? I'm still digging through books, but I haven't figured it out yet. The code compiles fine with MSVC6, but not 8. Bah, silly standard-compliant compilers.
matthughson
matthughson
Look through the functions for vector: there should be a couple that return iterators. Something like myVector.begin( );

Matt
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Mushu
Mushu
Quote:
Original post by matthughson
Look through the functions for vector: there should be a couple that return iterators. Something like myVector.begin( );

Okay, yeah, I'm an idiot. I somehow neglected to remember that you can advance random-access iterators in an easy manner (The C++ Standard Library, §7.2.5) :P

XoreDevelopment - use something like -

m_vFormList.erase( m_vFormList.begin() + i );

That should compile and give the desired results.
XoreDevelopment
XoreDevelopment
One Word:
Amazing

I have been to many other C++ forums, and replies are normally slow. When... in no time, 5 posts that actually help (instead of bashing or flaming the questionair) have been posted.

GD.net is definitely the best community I've been to.
Mushu
Mushu
Quote:
Original post by XoreDevelopment
I have been to many other C++ forums, and replies are normally slow. When... in no time, 5 posts that actually help (instead of bashing or flaming the questionair) have been posted.

We get whacked with large herrings when we bash/flame :(
matthughson
matthughson
@ Mushu - [wink] Heh, truth is I didn't really understand what you were asking, so I just posted an ambigious answer :P

@ OP - Yeah GD.net is the bomb. Just stay cool, and people will be more than happy to help yah out!

Matt
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.