have a problem, I want to create a function that can handle any type and react to it accordingly. So I have used a template on my function, the problem is that I am trying to tell my function that I can only fill a string with a character array if the type of the varible is a string.
Despite this it still churns out the old "error C2440: '=' : cannot convert from 'char [100]' to 'int'" message.
My code is such:
Can anyone help?Code://// ********* EditField: Displays the old value of a field and allows the user to modify a fields data. template <class T> void EditField(T value) { char buffme[100]; cout << "Old: " << value << endl; cout << "Enter new:->"; cin.getline(buffme,99); if(typeid(value).name() == typeid(int).name()) {value = atoi(buffme); return;} if(typeid(value).name() == typeid(string).name()) {value = buffme; return;} if(typeid(value).name() == typeid(float).name()) {value = atof(buffme); return;} }




Reply With Quote