问题调用std :: max

我编译我的野牛生成的文件在Visual Studio中,并得到这些错误:

… \ position.hh(83):error C2589:'(':'::'右侧的非法令牌
… \ position.hh(83):错误C2059:语法错误:'::'
… \ position.hh(83):error C2589:'(':'::'右侧的非法令牌
… \ position.hh(83):错误C2059:语法错误:'::'

相应的代码是:

inline void columns (int count = 1) { column = std::max (1u, column + count); } 

我认为这个问题是与std :: max; 如果我将std :: max更改为等效代码,那么就没有问题了,但有没有更好的解决scheme而不是更改生成的代码?

这里是我写的野牛档案:

 // // bison.yy // %skeleton "lalr1.cc" %require "2.4.2" %defines %define parser_class_name "cmd_parser" %locations %debug %error-verbose %code requires { class ParserDriver; } %parse-param { ParserDriver& driver } %lex-param { ParserDriver& driver } %union { struct ast *a; double d; struct symbol *s; struct symlist *sl; int fn; } %code { #include "helper_func.h" #include "ParserDriver.h" std::string error_msg = ""; } %token <d> NUMBER %token <s> NAME %token <fn> FUNC %token EOL %token IF THEN ELSE WHILE DO LET %token SYM_TABLE_OVERFLOW %token UNKNOWN_CHARACTER %nonassoc <fn> CMP %right '=' %left '+' '-' %left '*' '/' %nonassoc '|' UMINUS %type <a> exp stmt list explist %type <sl> symlist %{ extern int yylex(yy::cmd_parser::semantic_type *yylval, yy::cmd_parser::location_type* yylloc); %} %start calclist %% ... grammar rules ... 

你可能在某处包含windows.h ,它定义了名为maxminmacros。

在包含windows.h之前,您可以#define NOMINMAX定义#define NOMINMAX ,以防止它定义这些macros,或者可以使用一组额外的括号来防止macros调用:

 column = (std::max)(1u, column + count); 

在包含任何标题之前,在源代码顶部定义NOMINMAX符号。 Visual C ++将minmax定义为windows.h中的某个macros,并干扰您使用相应的标准函数。

 #define NOMINMAX