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?
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.