C++ class and the STL list
by Love "hyzen" Florg · in Technical Issues · 01/18/2002 (4:47 pm) · 5 replies
I need a class containing a list of references to objects of the same class.
What should I do? Have I forgotten something (probably) or do I have to make it in another way?
//hyzen
class Foo {
list<Foo> fooList;
};This doesn't work because Foo isn't defined in it's own definition. All right.class Foo {
list<Foo&> fooList;
};This doesn't work because the list template doesn't like references.class Foo {
list<Foo*> fooList;
};This DOES work but I don't like it because now I'll get references and pointers to pointers when using the list functions.What should I do? Have I forgotten something (probably) or do I have to make it in another way?
//hyzen
About the author
#2
01/19/2002 (3:38 am)
Yes I know, I read Joel Baxter's thread concerning that. This is a general C++ template question.
#3
For some good info on using STL lists of pointers to game objects check out the chapter 1.4 "Using the STL in Game Programming" in the Game Programming Gems book (book 1). Or use a linked list instead if you can.
Mike
01/24/2002 (5:37 pm)
I had that same problem once. The thing is you're going to have to do it that last way if you want to use STL. STL lists choke if you create a list of objects. You're going to have to use the list of pointers. I know it sucks. For some good info on using STL lists of pointers to game objects check out the chapter 1.4 "Using the STL in Game Programming" in the Game Programming Gems book (book 1). Or use a linked list instead if you can.
Mike
#4
01/24/2002 (5:43 pm)
Oh by the way I have a general use collection template class I wrote that is based on the Game Programming Book example that worked well in one of my projects. Drop me a line at mike.nelson@21-6.com and I can email it to you if you want to check it out.
#5
I used pointers and got it working so I think I'll let it be for now. If I decide to change the code sometime I'd be glad to try your template.
01/29/2002 (6:41 am)
Thanks for the replies!I used pointers and got it working so I think I'll let it be for now. If I decide to change the code sometime I'd be glad to try your template.
Associate Tim Newell
Max Gaming Technologies
-Tim aka Spock