From: "A.Appleyard" Organization: Materials Science Centre To: djgpp AT delorie DOT com Date: Thu, 10 Oct 1996 16:20:02 GMT Subject: Re: A pointer of variable type - is it possible? Message-ID: <982A4C7275@fs2.mt.umist.ac.uk> paradox AT direct DOT ca (Wesley Terpstra) wrote:- > ... the 3d object only has ... mass, > moment of inertia, velocity, acceleration, angular acceleration, > points, lines, 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. Derived classes supply part of this need:- class object {public: short sort; float mass, inertia, speed, accel, ....;}; class spaceship: public object {char*name; int weapon_power; .....;}; class star: public object {int spectrum_class; float radiation_output; ....;}; A spaceship and a star also thereby have the fields that an object has. If these are declared:- object *X; star Rigel,*S; spaceship Explorer,*C; then X=&Rigel; X=S; X=&Explorer; X=C; are possible, but not S=X; C=X; Rigel=*X; Explorer=*X; If you define these codes:- enum{_unknown=0, _spaceship=1, _star=2, _missile=3; .....}; and if you make sure that spaceship.sort==1, star.sort==2, etc, always, then (I think) you can convert back:- switch(X.sort) { case _spaceship: S=(spaceship*) X; .... handle a spaceship ....; break; case _star: C=(star*) X; .... handle a star ....; break; etc etc;}; .................................................................. > I considered using a signature like: > signature object_data_ptr { > void *object_data; > const char *identifier; > void load(DB *); > void save(DB *); }; What's a signature? What variant of C does it occur in?