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

Reply via email to