Is there a language with something like the following construct?
var_type(TYPE_1, TYPE_2,..., TYPE_N) obj;
and now its possible to:
TYPE_17 staticTypeVariable17;
obj = staticTypeVariable17;
TYPE_3 staticTypeVariable3;
obj = staticTypeVariable3;
without obj
being a pointer of some base class and with no need for casting if the types used are from the predefined set.
So basically an object that can switch it’s type amongst a predefined set of types.
2
The construct you are referring to is called a discriminated union and is part of quite a few languages and can be created in more.
Among the languages that support discriminated unions are C++, Visual Basic, ML and Haskell and those are just the languages that popped up in the wikipedia article.
0