Magic type return

Tobias Pankrath tobias at pankrath.net
Tue Jul 17 07:22:05 PDT 2012


On Tuesday, 17 July 2012 at 13:56:29 UTC, Andrea Fontana wrote:
> 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
>
> I just know how to do this:
>
> string s = know.value!string();

You can't. You could do

string s;
known.value(s);

where

void value(T)(ref T t);


More information about the Digitalmars-d-learn mailing list