Re: returning a type
"U.Mutlu" <for-usenet@mutluit.com> writes:
2) Is it possible to declare/define a type from a string literal?
Ie. you have a const char* psz = "int" and want declare/define a variable
of that type that's in the string, ie. in this case int.
When a C++ compiler is at hand at runtime, code can be
generated and compiled to a run-time library (when support
for such libraries is available) and then loaded and called.
However, the whole idea of types is some /static/ safety,
which means that types should be fixed at write time.
Otherwise, one can just pass around void pointers and cast
them to whatever needed, when needed. (Such casts might not
be portable, but often will work.) Or one can use B or BCPL.
To implement run-time typing in OOP, the usual solution is
polymorphism (?tell, dont't ask?), which also can be used in C++.
If you would describe the problem that is to be solved,
preferably with a small SSCCE, then often someone will be
able to finde a more C++-like solution to the actual problem.