|
STL and BITMAPs |
Don Freeman
Member #5,110
October 2004
|
Is it possible to use STL with allegro BITMAP structures? such as: list<BITMAP> images; //or list<BITMAP*> images; list<BITMAP>::iterator iter // or list<BITMAP*>::iterator iter; images.insert(iter,*(load_bitmap("SomeImage.bmp",NULL))); // or images.insert(iter,load_bitmap("SomeImage.bmp",NULL)); I've tried but can't seem to get it to work correctly. I am not very experienced with using STL... I can get it to store an image, but when you add another one, it replaces all the others in the list!:o Thanks as always, -- |
X-G
Member #856
December 2000
|
BITMAP * -- |
Rampage
Member #3,035
December 2002
|
-R |
Don Freeman
Member #5,110
October 2004
|
So, basically no... The allegro BITMAP structure just holds the basic layout...it also holds the image data, but in an array... I am confused. I would have to write a "wrapper" class around BITMAP? And if so, how would I handle creation/deletion properly? -- |
X-G
Member #856
December 2000
|
Store BITMAP *. Iterate through the list and destroy_bitmap them. That's the easiest way. -- |
Rampage
Member #3,035
December 2002
|
The allegro functions work with pointers to BITMAP structures, not with the structures themselves. You just have to do the same with the STL functions, you must work with pointers. -R |
Trezker
Member #1,739
December 2001
|
There is no problem. Creation: Removal: I think that's right... |
Don Freeman
Member #5,110
October 2004
|
This is how I get it to SORTA work...
-- |
Rampage
Member #3,035
December 2002
|
Don't you have to create the iterator after filling the list? You don't need an iterator to add elements to a list, just to get them out. -R |
Trezker
Member #1,739
December 2001
|
Well DUH! You're destroying it. |
Don Freeman
Member #5,110
October 2004
|
Doesn't matter...both do the same thing...(creating the iterator before or after) -- |
Rampage
Member #3,035
December 2002
|
Oh yeah, Trezker is right! You are destroying the bitmap after the insertion! Your list contains only invalid pointers. [edit] X-G mentioned the solution in his second post on the topic. -R |
Don Freeman
Member #5,110
October 2004
|
Yeah...I'm special::) We can do that on Mars...8-) Ok....here is the "working" code...
Thanks again to all of you:-*, -- |
Trezker
Member #1,739
December 2001
|
EDIT: This thread is fast. |
Don Freeman
Member #5,110
October 2004
|
Trezker: So you would call delete on the bitmap object? Yes...I should use the push_back instead... -- |
Rampage
Member #3,035
December 2002
|
You should use destroy_bitmap(), not delete... -R |
Trezker
Member #1,739
December 2001
|
Oops, no delete. |
|