Function overloading fails to compile?
I have something like this in the code:
Code:
...
template <class T> const T& min ( const T& a, const T& b ) { return (a<b)?a:b; }
...
class ...
{
...
double min(void){return(MinVal);}// MinVal is a (double type) member of the class
...
}
...
Essentially the first min() is a function that takes two arguments and returns the smaller one, and the second min() is a class member function that takes no arguments and returns a member variable. The code compiles and works fine under Cygwin. But VC 2010 comes back with this error:
Code:
warning C4003: not enough actual parameters for macro 'min'
:confused:
It seems that VC does not know I was trying to define a member function, instead it thinks I wanted to use the first min() incorrectly. :confused: What's going on? Please help! Thanks!
Re: Function overloading fails to compile?
VC++ defines a preprocessor macro named min (that essentially does the same thing your template function does) in some header file, don't know which one for sure at the moment. Preprocessor macros are expanded before the actual compiler gets hands on the code at all, so they can't be overloaded.
Try to add this line after the includes in your source file:
And while you're at it, you can do the same thing with max as well.
HTH
Re: Function overloading fails to compile?
Or just do this *before* your includes:
#define NOMINMAX
I ridicule MS frequently for this particular decision. There's no good reason these macros should exist.
Re: Function overloading fails to compile?