www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/10/08:14:38

From: paradox AT direct DOT ca (Wesley Terpstra)
Newsgroups: comp.os.msdos.djgpp
Subject: A pointer of variable type - is it possible?
Date: Thu, 03 Oct 1996 08:45:36 GMT
Organization: Canada Internet Direct, Inc.
Lines: 37
Message-ID: <325379bb.732349@news.direct.ca>
NNTP-Posting-Host: nan-as-01a04.direct.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

	I recently ran into a scenario where I need a pointer of a
variable type.  The case is this:  I am writing a 3d library with c++
classes.  The objects created by the 3d library have children,
siblings, and parents. (Ie objects connected to objects and objects
floating around in a universe etc)  Now, this all works great except
that I need to be able to have the 3d library "connect" another class
to the existing 3d object class.  You see, the 3d object only has
stuff pertenant to caluclating effects in the 3d world (ie: mass,
moment of inertia, velocity, acceleration, angular acceleration,
points, lnes, polys, textures, etc).  I also need to add the ability
for 3d objects to have a dynamic section.  This will let spaceships
have data members like weapon_power, armor_power, etc. and let stars
have stuff like radiation_output, percentage_chance_of_flare, etc.  I
considered using a signature like:

signatue object_data_ptr
 {
  void *object_data;
  const char *identifier;

  void load(DB *);
  void save(DB *);
 };

	Placing a signature like that in the 3d object class would
allow me to read the object's non-3d data, etc from object_data
(assuming I use the identifier string to determine what the class
being abstracted was).  However, signatures are NOT portable beyond
GCC and I am looking for a more elegant solution than taking pointers
to functions and using them to save/load.  This is partly because
comparing an identifier string against a list of known objects limits
me to only objects which I specifically add in some strange table and
it would also incure alot of overhead.  I have heard about something
called polymorphic classes.  Would this be able to give me the power I
need?  I also noticed an operator called typeof() could this be used
to make my local information portable, yet fast?  If you know a way
that I could do this, please tell me! :)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019