S
Scott Kilpatrick
Let's say I have a hacked-up polymorphic container that holds variables
of type:
struct poly {
union {
int *i;
double *d;
complex<double> *c;
} value;
char type;
};
Each time a value gets added to the container, it mallocs a new value,
sets the type char, and sets the pointer to that new value. How, then,
do I write a destructor for poly? Do I do a switch on type and delete
value.x if it's that type? Also, how do you delete a poly if it
contains both pointers and non-pointers (non-pointers to native types
that is)?
Scott
of type:
struct poly {
union {
int *i;
double *d;
complex<double> *c;
} value;
char type;
};
Each time a value gets added to the container, it mallocs a new value,
sets the type char, and sets the pointer to that new value. How, then,
do I write a destructor for poly? Do I do a switch on type and delete
value.x if it's that type? Also, how do you delete a poly if it
contains both pointers and non-pointers (non-pointers to native types
that is)?
Scott