SOLVED std::max() workaround
Yes, I've been trying to break my VB whoring ways (reformatting the HD helped a little) so I've been working through Accelerated C++
Problem is, one of the examples won't compile - it requires a call to std::max() which, apparently, doesn't exist. (And yes, I've defined <algorithm>, first thing I checked)
So, I did a little googling, and found out that in MSVS6, the std::min() and std::max() functions were removed because they conflicted with <windows.h>
So, found their workaround, _cpp_min() and _cpp_max(), but is there a workaround around their workaround? Can I overload the function with something similar to a typedef (templates, perhaps)?
Wait... can you even overload a function with no parameters if the means of determining which version of an overloaded function to use IS the parameters?
"No" would be my guess... am I right?
EDIT: solved! Yay!
[Edited by - Mushu on November 30, 2004 10:11:15 PM]
To get around the windows.h nightmare, I do one of a few things:
1) Avoid including it at almost any cost
2) Failing that, I use #undef min and #undef max, and that should make std::min and std::max work a treat in that compilation unit.
1) Avoid including it at almost any cost
2) Failing that, I use #undef min and #undef max, and that should make std::min and std::max work a treat in that compilation unit.
I don't include it. I think it's included in one of the other headers I put in there (or my compiler is evil).
I'll try the #undef, but I'm not entirely sure that will work - min() and max() don't appear to be members of std at all. I'll know in several minutes, regardless. Thanks
EDIT: nope; I was right. min() and max() are no longer members of the standard library.
I'll try the #undef, but I'm not entirely sure that will work - min() and max() don't appear to be members of std at all. I'll know in several minutes, regardless. Thanks
EDIT: nope; I was right. min() and max() are no longer members of the standard library.
Defining std::min() and std::max() for yourself isn't that hard. Ex:
template <typename T> inlineconst T & min(const T & left, const T & right) { return (right < left ? right : left);}
Yeah, I had an inkling of a feeling there was a solution with templates, but those don't come up for another couple chapters.
...let me try that code anyway, after all you did take the time to type it for me [grin]
EDIT: Yep. That appears to have worked! I'll just switch the signs to get me max(), then... Oh, and if Washu is reading this I still despise templates, just so we can keep that straight.
EDIT2: std::_cpp_min() and std::_cpp_max() seem to work fine too. I wonder why I didn't notice those sooner? Oh well... Thanks everyone!
...let me try that code anyway, after all you did take the time to type it for me [grin]
EDIT: Yep. That appears to have worked! I'll just switch the signs to get me max(), then... Oh, and if Washu is reading this I still despise templates, just so we can keep that straight.
EDIT2: std::_cpp_min() and std::_cpp_max() seem to work fine too. I wonder why I didn't notice those sooner? Oh well... Thanks everyone!
Quote:Original post by SiCrane
Defining std::min() and std::max() for yourself isn't that hard. Ex:template <typename T> inlineconst T & min(const T & left, const T & right) { return (right < left ? right : left);}
Don't forget to do
#undef min #undef max
Before you define your new template functions for min and max, otherwise your preprocessor will do some tomfoolery with the function names.
Actually it works fine without it. The problem was std::min() and std::max() are just renamed in MSVC6; _technically_ it would be a problem if "windows.h" was included, but that wasn't where my problem was stemming from.
Just a stupid failure to recognize that std::_cpp_max() == std::max() - They just renamed the darn functions.
That done, I think I'm gonna hit the sack. Thanks for the help!
Just a stupid failure to recognize that std::_cpp_max() == std::max() - They just renamed the darn functions.
That done, I think I'm gonna hit the sack. Thanks for the help!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement