Jump to content
  • Advertisement
Sign in to follow this  
XoreDevelopment

Odd Errors

This topic is 4486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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).

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
@ 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!