9月 2019

由RapidJSON发现的成员函数与宏冲突问题

在使用RapidJson的时候,发现了一个之前很少注意到的问题:

F:\Projects\test\rapidjson-1.1.0\include\rapidjson\document.h(982,70): error : too few arguments provided to function-like macro invocation
if (a < static_cast(-std::numeric_limits::max())

乍一看好像不是很眼熟的错误提示,没看懂什么意思,惯例搜索引擎查,于是很快发现了这个: https://stackoverflow.com/questions/1394132/macro-and-member-function-conflict ,简单一看就反应过来了,原来是成员函数名(这里是max)和之前不知在哪定义过的同名max冲突了,编译器把本该作为成员函数调用的max当成作了替换,于是就出现了上面的错误。

Continue reading…