casting - How to define a data type from file in C++? -


i'm making class object should contain value, value read externally in form of value, datatype, datatype tells me how interpret given value (int, float, double, char, etc).

i wonder if possible make casting @ run time , how it, honest i'm bit lost , information i've found topic seems bit bit of overkill.

any ideas ? thanks.

look discriminated unions , boost::variant in particular, gist is:

struct value {   enum { int, float, double, char, etc } type;   union {     int int_;     float float_;     double double_;     char char_;     etc etc_;   } value; }; 

then check type before doing operation, , select right union member based on has been stored in it.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -