错误信息:
error C2059: syntax error : 'constant'
*\JsonCpp\Value.h(126) : error C2574: 'Json::Value::Value(void)' : cannot be declared static
原因:
目前的项目在用mongodb和jsoncpp,使用的mongodb版本的头文件中有一个宏定义“#define null (0)”,同时jsoncpp的Value类有一个常量“static const Value null;”,两个null命名冲突导致的问题,即当包含的头文件顺序使得mongodb的null宏在jsoncpp的null常量之前被包含,那么jsoncpp中的null标识符会被替换成“(0)”,从而导致语法错误,如下面的例子所示:
#define null (0) //"mogodb/include/mongo/stdafx.h" class Value //"JsonCpp/Value.h" { private: static const Value null; };
上面例子产生的编译错误:
error C2059: syntax error : 'constant'
error C2574: 'Value::Value(void)' : cannot be declared static