Christian Christmann wrote in message <[EMAIL PROTECTED]>... >Hi, > >when I run this code: > >#include <iostream> >using namespace std; > >template <class T> >T GetValue(int a) >{ > if (a = 1) > return 1; > else > return 2.55; // line 11 >} > >int main() >{ > int a = GetValue<int>(1); // line 16 > cout << "\nInt a : " << a << endl; > > double b = GetValue<double>(2); > cout << "\nDouble b: " << b << endl; > > return 0; >} > >I get the gcc warning: >temp.cpp: In function `T GetValue(int) [with T = int]': >temp.cpp:16: instantiated from here >temp.cpp:11: warning: converting to `int' from `double' > >Why? >Line 16 should not be reached when the function is called >from line 11. >Is there any way to avoid this warning? >Thank you >Chris
You missed a little fine point from Peter J.: template <class T> T GetValue(T t) { // <--note the parms if (t == 1) // <-- note the '==' compare, NOT '=' assignment. return 1; else return 2.55; } -- Bob R POVrookie _______________________________________________ Help-gplusplus mailing list Help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus