Magic type return
bearophile
bearophileHUGS at lycos.com
Tue Jul 17 07:23:05 PDT 2012
Andrea Fontana:
> class Known
> {
> void* data; // external data by c api
> int type; // 0 for int, 1 for string, etc. ..
> }
>
> How can I implement a method like this?
>
> Known known; // <-- suppose known.type == 1;
> string s = known.value(); // <-- automatic
To do this Known.value() needs to return different types
according to the run-time value of Known.type. This is not
possible in a statically typed language... You need to find other
solutions.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list