Jump to content
  • Advertisement

Archived

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

nick_coleman

vectors inside structs

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

I''m writing a program that started off as C and swiched to C++, I have a struct that has vector members I malloc the struct, but sometimes I''m getting a seg fault when I try to push_back(item) on the vector. I can change the other variables in the struct and chage. The problem happens when I am dealing withe a pointer to the stuct (called line): line->members.push_back(item); and not necessaritly the first push. Shouldn''t I be able to push on an arbitary number of items? I appreciate any help I was up to 11 in the morning last night and It''s 6:40am here again, and this was due two days ago! Thanks Nick

Share this post


Link to post
Share on other sites
Advertisement
Never use malloc() in C++. The vector constructor isn't being called. use new instead.

Oh, and of course, never use free() either. Use delete or delete[] instead.

[edited by - sneftel on July 16, 2002 3:12:57 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Sneftel
Never use malloc() in C++. The vector constructor isn''t being called. use new instead.

Oh, and of course, never use free() either. Use delete or delete[] instead.



Well, if you''re implementng operator new() and/or operator delete() [admittedly pretty advanced stuff...], then you''ll
need to fall back to malloc/free to avoid infinite recursion.



~~~~
Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
quote:
Original post by tangentz

Well, if you''re implementng operator new() and/or operator delete() [admittedly pretty advanced stuff...], then you''ll
need to fall back to malloc/free to avoid infinite recursion.



Very true... tho given that he didn''t even know to use new, I''m guessing it''ll be a little while before he has need for overloading new or delete.

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!