Problem calling std::max: Illegal token on right side of ::

Q:

I compiled my bison-generated files in Visual Studio and got these errors:

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

The corresponding code is:

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

I think the problem is with std::max; if I change std::max to equivalent code then there is no problem anymore, 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 ...


A:

You are probably including windows.h somewhere, which defines macros named max and min.

You can #define NOMINMAX before including windows.h to prevent it from defining those macros, or you can prevent macro invocation by using an extra set of parentheses:

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


From: http://stackoverflow.com/questions/2789481/problem-calling-stdmax

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值