When writing a Graph template class, in order to enable the user to customize the type of distance, such as int or double or even other high-precision rational number encapsulation class,
I defined the type of distance as template parameter t_dist and used library functions in the standard library
STD :: numeric_limits < t_dist : : Max ()
To define the maximum distance
Template<TypeName t_dist>ConstTypeNameTopologicalgraph<t_dist: :DistanceTopologicalgraph<t_dist: :max_distance= (STD::numeric_limits<t_dist: :Max()/static_cast<t_dist> (2));
In a unit test, a Windows.h is included in the trace class that tracks and records the execution state when the program crashes.
And I'm using the include model to implement the template, and in the test project Trace.h before GRAPH.H,
Causes Std::numeric_limits<t_dist>::max () to conflict with the MAX () macro in Windows.h, so the macro substitution done in the preprocessing phase causes the statement to have an inexplicable syntax error.
Later on, StackOverflow looked up a bit,
Useful #undef Max, there are compiler switch macros that use other Windows, have Windows.h in the CPP file, and say don't include Windows.h ...
Finally found a beautiful solution--
Http://stackoverflow.com/questions/1394132/macro-and-member-function-conflict
In fact, just use parentheses to enclose Max ...
(std::numeric_limits<t_dist;::Max )()
So, still need to add parentheses AH ~
Previously only know the definition of macros to be wrapped up layer by bracket, did not expect to use the macro or syntax structure and macro-similar syntax elements (such as function calls) this time!
..................
After solving this problem, it suddenly appears that the package class cannot use Std::numeric_limits<t_dist>::max () to get the correct maximum value ...
Resolving name pollution caused by macro definitions in C + +