|
-
December 16th, 2010, 01:53 PM
#1
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'

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. What's going on? Please help! Thanks!
-
December 16th, 2010, 02:54 PM
#2
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
Last edited by Eri523; December 16th, 2010 at 05:03 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
December 16th, 2010, 03:08 PM
#3
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.
-
December 16th, 2010, 03:18 PM
#4
Re: Function overloading fails to compile?
Thank you both!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|