Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Zeblar Nagrim

vector list problem

This topic is 6012 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

Hello, I have problems with the std::vector class:


CGUIWnd wnd = CGUIWnd(idwnd,x,y,w,h);

CGUIButton button = CGUIButton(idbutton,m_aWnds.back(),x,y,w,h);
m_aButtons.push_back( button );

What happens? I create a window and than a button. The window are registered as the parent for the button. CGUIButton is derived from CGUIWnd. In the CGUIButton class I have a pointer to a CGUIWnd (that is the parent of the button). This works fine first time the function is called but when the second window is created the first button (the button on the window) get crap values! Something happens when the vector object m_aButtons inserts a new element to the list. I think it is because of the CGUIWnd pointer in the CGUIButton class. When a new element is inserted in m_aWnds the pointer in CGUIButton class isn´t valid anymore. Please help! Zeblar Nagrim, Lord of Chaos

Share this post

Link to post
Share on other sites
With the limitted code you''ve put here, it appears that your problem is in the definition of your vector. It looks like you''re defining a vector of objects, not pointers, and pushing-in derived class objects. This will not work. In order to use polymorphism in STL containers you have to use pointers (or smart pointers), not objects.

Share this post

Link to post
Share on other sites
Thanks for your advise!

You want me to change from,
   std::vector<CGUIButton> m_aButtons;   
   std::vector<CGUIButton*> m_aButtons;   

Edited by - Zeblar Nagrim on January 30, 2002 5:39:21 PM

Share this post

Link to post
Share on other sites

  • 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!