Problem calling std :: max

I compiled the files created in the bison in Visual Studio and received these errors:

... \ position.hh (83): error C2589: '(': illegal token on the right side of '::'
... \ position.hh (83): error C2059: syntax error: '::'
... \ position.hh (83): error C2589: '(': illegal token on the right side of '::'
... \ position.hh (83): error C2059: syntax error: '::'

Relevant Code:

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

I think the problem is related to std :: max; if I change std :: max to equivalent code, then there are no more problems, but is there a better solution instead of changing the generated code?

Here is the bison file I wrote:

 // // 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 ... 
+48
c ++ windows visual-c ++ bison
May 7, '10 at 14:54
source share
2 answers

You probably include windows.h somewhere that defines macros called max and min .

You can #define NOMINMAX before enabling windows.h to prevent it from being defined by these macros, or you can prevent the macro from being called with an extra set of parentheses:

 column = (std::max)(1u, column + count); 
+102
May 7 '10 at
source share

Define the NOMINMAX symbol at the top of your source before including any headers. Visual C ++ defines min and max as macros somewhere in windows.h, and they prevent you from using the corresponding standard functions.

 #define NOMINMAX 
+17
May 7 '10 at 2:59 p.m.
source share



All Articles