Hello. I wonder if there is any way to declare variable of type specified by string value. For example, I get "float" and need to declare float-variable. Of course, I can do
1 2 3 4
if (str == "float")
{
float f = 0;
}
for each variable type, but maybe exists better solution. Or at least get sizeof(float). Thanks.
You are better off designing a full polymorphic class hierarchy for this. I am assuming of course that you want the variables to last longer than the scope of the if statement and also that you plan to allow the user to then modify these variables - sounds very much like a strongly-typed scripting language of your own design ;)