Code
# Include <iostream>
# Include <algorithm> // STD: min
# UNDEF min
Int main ()
{
Float a = 15.0f;
Float C;
C = STD: min (10, );
Printf ("% F", B );
Getchar ();
}
Error Message
Error 1 error c2780: 'const _ ty & STD: min (const _ ty &, const _ ty &, _ Pr) ': expects 3 arguments-2 provided
Error2error c2782: 'const _ ty & STD: min (const _ ty &, const _ ty &) ': Template parameter' _ ty 'is ambiguous
3 intelliisense: no instance of overloaded function "STD: min" matches the argument list
4 intelliisense: Too few arguments in function call
Unction template (C ++ 98)
Template<ClassT>ConstT & min (ConstT &,ConstT & B ){Return! (B <)? A: B;// Or: return! Comp (B, )? A: B; for version (2)}
Error Analysis
The STL template used by min. In the prototype of the algorithm, the parameters A and B should be of the same type, c = STD: min (10, ); 10. A mismatch with the type causes the following error.
Modification Method
Method 1
C = STD: min (10.0f, );
Method 2
Float B = 10;
c=std::min(b,a);
Method 3
C = STD: min (float) 10.0, );
Compiler error c2780 of STD: min and STD: Max