Mail Archives: djgpp/1999/07/07/11:56:53
Denis Lamarche wrote:
> > struct vars
> > {
> > char *vname;
> > double *var;
> > };
> >
> > struct vars variables[]
> > = {
> > {"drive", &drive},
> > {"room", &room},
> > {"picture", &picture},
> > {"house", &house}
> > };
> >
> Ok...I see were I went wrong....ok, but would this work for structures
> too? If I assign the pointer to that structure to *var, can I later go
> variables[0].var->x=10? if I assign the structure pointer to var then
> it will turn into a double right?...how would I re-convert it int that
> structure without knowing what that structure is?
Now you're getting complicated. The only way I can think of is to use some "Variant" data
type. That would consist of a giant union of every possible datatype, and a
type-specifier. Every time you wanted to make an assignment, or read a value, you would
have to go through a giant switch and choose the right union member.
I can think of a neat way of doing it in C++ using a class and some overloaded
operators. It would still require the union, but now all you would have to do is overload
the '=' operator for every datatype, and just make the assignment into that union member.
--
-Rolf Campbell (39)3-6318
- Raw text -