Run Time Type Information? Calculator program

Hello, i'm trying to make a calculator program and I have a question: how do I declare the type of a variable based on input? I have tried many things, template functions and the new auto and decltype keywords, but it just doesn't work.

1
2
cin >> getThisTypeFromInputByUser
//How do I do this??? 


The reason is I want to know if the operand is going to be either an int or a double before I create an object of the template class, and it has to be known at run time. Can anyone help me or tell me about some RTTI libraries?
Why not make it only double?
So you want the program to read the user input and then determine what type of data it is? That would be impossible since neither the compiler not the running program would know which implementation of the << operator should be used to read the data in the first place. You could read the data in as a double, then determine if it's an integer with some mathematical trickery, then go from there. You have to be careful when casting from double to int though.
You have to be careful when casting from double to int though.


Why is that? Doesn't the compiler truncate the digits after the decimal point?
Is that how people make real calculator applications? Do they just do a cast on a double?
No they don't, which is why we are saying that you should not do it that way either.
Topic archived. No new replies allowed.