[gameprogrammer] Re: General Purpose Double Linked List Class

man, 27 02 2006 kl. 21:52 +0100, skrev Torsten Giebl:
> Hello !
> 
> 
> 
> I have one problem with this class.
> 
> Adding a single object from a single class,
> works without problems. But in my game i have
> the following structure :
> 
> class Bob
> class Plattform : class Bob
> class Big_Plattform : class Plattform
> 
> class Bonus : class Bob
> class Heart_Bonus : class Bonus
> 
> 
> So adding single Bobs works without problems,
> but when i add a Plattform for example,
> it seems to loose the Plattform Data and
> only the Bob Data is there.
Don't worry the data i still there!

The thing is, because your list holds Bob(s) - there is no way for your
compiler to know that this is, for example, a Platform - you need to
cast the pointer first.

So when you retrieve a Bob pointer you should cast it to a Platform:
Bob *bob = <from somewhere>
Platform *platform = static_cast<Platform*> (bob);

Of course, it is up to you to make sure that the bob pointer is actually
a Platform and not, for example, a Bonus.

-- 
Rasmus Toftdahl Olesen <halfdan@xxxxxxxxxxxx>
halfdans.net



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: