Skip to main content
gamedev.net
🔒 Locked

a question about list class

Started by alnite Dec 9, 2002 at 8:15 PM 1 replies 150+ views
Original Post
alnite
alnite
This is what I have: std::list< RECT > rectlist; You guess it, I am making a list of RECTs. However, I am having trouble in inserting. I tried this: rectlist.push_back( RECT(0,0,10,10) ); Of course it didn't work, so I tried this: RECT dummyrect; rectlist.push_back( dummyrect ); then I worried, what if I tried to push_back dummyrect multiple times? Does the list make a copy of my dummyrect when I insert it?
My compiler generates one error message: "does not compile." [edited by - alnite on December 9, 2002 10:16:54 PM]
non_interleaved
non_interleaved
Well... you are probably looking for push_back() or push_front(). push_down() is not a instance method of std::list.

Second of all... STL containers make copies of everything when you add things to them. So if you are worried about an expensive constructor getting called all of the time, then you probably want to hold pointers and deal with free()ing the pointers when you need to.
alnite
alnite
lol, yeah, I meant push_back.

quote:

STL containers make copies of everything when you add things to them.



So, it''s ok if I do this?

RECT dummyrect;
dummyrect.left = 10; // and top, bottom, and right
rectlist.push_back(dummyrect);
dummyrect.left = 20; // and top, bottom, and right
rectlist.push_back(dummyrect);
dummyrect.left = 30; // and top, bottom, and right
rectlist.push_back(dummyrect);

so at the end, my rectlist will contain three rects?


My compiler generates one error message: "does not compile."

Topic Locked

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

Sign in to reply to this topic.