   Can templates handle floats?
  Hii have code here wich uses template type function whit floats but its not accurate. template <class T> Count (T a,T b){ return(a+b);}cout<<Count(5.8,3.0)<<endl; // doesnt cout 8.8  how do u fix that, is it bossible?  
  i think the correct syntax for calling templates is:Count<float>(3.8, 5.0);otherwise it may just be defaulting to int or something bizzarro.-me[edited by - Palidine on November 21, 2002 3:01:50 PM];  Templates work with any type, but I believe you need to specify the return typetemplate<class T>T Count(T a,T b) {  return a + b;}    If it doesn't print out 8.8 exactly, then it's due to rounding errors and there's nothing you can do. Making the plus-operation outside the template wouldn't fix it.By the way, in your example you pass doubles to the template instead of floats.Palidine, function template arguments can be deducted from the input values. Had the input values been integers, T would've been int and then the explicit template argument would've been necessary to get the values to be added together as floats.[edited by - civguy on November 21, 2002 3:07:37 PM];quote:Original post by Craazertemplate  Count (T a,T b){ return(a+b);}cout< Pay heed to your compiler warnings.You didn''t specify a return type, the compiler assumed an int return (holdover from C).    Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]C++ Stuff [ MinGW | Loki | SDL | Boost.  | STLport | FLTK | ACCU Recommended Books ];quote:Original post by civguy  Templates work with any type, but I believe you need to specify the return type   template<class T>T Count(T a,T b) {  return a + b;}  Oh yes i was missing the ''T'' type :o)thanks it works now!