vectors inside structs
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
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]
Oh, and of course, never use free() either. Use delete or delete[] instead.
[edited by - sneftel on July 16, 2002 3:12:57 PM]
Thanks
It''s weird though, it''s not the first push that fails, I''ll try that though.
It''s weird though, it''s not the first push that fails, I''ll try that though.
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!
神はサイコロを振らない!
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement