I am trying to compile some older C++ code (probably from around 2001-2002) on a Debian GNU/Linux stable system. When compiling, I get the error:
In file included from /usr/include/c++/4.7/vector:66:0,
from ../FooMath/FooBar.h:23,
from FooBar.cpp:2:
/usr/include/c++/4.7/bits/stl_bvector.h: In member function ‘std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::max_size() const’:
/usr/include/c++/4.7/bits/stl_bvector.h:685:2: error: ‘max’ is not a member of ‘__gnu_cxx::__numeric_traits<long int>’
Hunting down the problem, I came across this piece of code in one of our own header files, which I assume is related to this problem:
#if defined(IRIX) | linux
signed max(signed a, signed b);
long max(long a, long b);
double max(double a, double b);
float max(float a, float b);
signed min(signed a, signed b);
long min(long a, long b);
double min(double a, double b);
#define __min min
#define __max max
float min(float a, float b);
#endif
and at lots of other places, I see calls to a __max() function with two arguments.
My educated guess is that I can replace all these calls to __max() with calls to std::max() and that I should include the <algorithm> header.
My two questions are:
At the line 685 in bits/stl_bvector.h you have :
__gnu_cxx::__numeric_traits<difference_type>::__max
Your ugly macro is replacing __max by max, hence the error.
You can effectively replace all your __max in your code by std::max, but just to be sure not to dismantle everything, you could first rename __max by __my__max, just to be sure (in your macro too). That way you will keep using the self-defined min/max functions.
Another solution would be to undef your macro before including stl headers and reenabling it after.