Skip to main content
gamedev.net
🔒 Locked

Generic Linked List class

Started by neoGriff Sep 22, 2000 at 10:58 AM 0 replies 200+ views
Original Post
neoGriff
neoGriff
I am using a linked list to contain all of the objects in my 3d engine, but I never really learned how to use templates. I used a book I have to understand the syntax, but I am getting errors from msvc when I try to access the members of an object embedded deep within templated classes. The Linked list class can accept any kind of object (camera, light, or just a regular 3dobject) in its Insert member function, and then sends this to the constructor for the Node class which is also templated. The problem is when I try to access individual data members of an object. ObjectList.GetCurrentNode()->object.(here''s the problem)pos.x; ObjectList: instance of linked list class GetCurrentNode(): returns current Node object: some kind of 3d object pos: instance(?) of struct that only occurs in one of the 3 kinds of 3d objects I am using x: member of pos struct I think the reason I am having problems is that I might not be able to access things like the struct inside of the object because not every kind of object I''m using has that struct as a member. If anyone could quickly give me an answer to my problem or suggest a better way of handling this stuff, I would be most appreciative. Thank you, Mike Griffin griff@umr.edu
Yanroy
Yanroy
This sounds like a job for one or more of the following:

a. Polymorphism
b. Multiple Linked Lists
c. dynamic_cast<>

If you have a templetized linked list that lets you store different types of objects, that is probably not a good idea. You should have it store a base class pointer and then have the different types of objects you want to store derive from the base class. Then they can be safely stored. To do this the way you want though, you would need a dynamic_cast<> on the return value of GetCurrentNode().

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Topic Locked

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

Sign in to reply to this topic.