Skip navigation

Monthly Archives: February 2012

A simple template, to find the minimum of 3 numbers.

Can you find the bug in this code?

  template<typename T> inline T min3( const T& a, const T& b, const T& c )
  {
    if( a < b && a < c )  return a ;
    else if( b < a && b < c ) return b ;
    else return c ;
  }

Hint: Actually I’m not going to give you any hints. But it is possible for the above function to return the incorrect value.