提问人:Haiyang 提问时间:5/7/2010 最后编辑:Michael MrozekHaiyang 更新时间:5/7/2010 访问量:35243
调用 std::max 时出现问题
Problem calling std::max
问:
我在 Visual Studio 中编译了 bison 生成的文件并收到以下错误:
...\position.hh(83):错误 C2589:'('::' 右侧的非法标记 ...\position.hh(83):错误 C2059:语法错误:'::' ...\position.hh(83):错误 C2589:'(':' 右侧的非法标记
...\position.hh(83):错误 C2059:语法错误:'::'
对应的代码为:
inline void columns (int count = 1)
{
column = std::max (1u, column + count);
}
我认为问题出在std::max上;如果我将 std::max 更改为等效代码,那么就没有问题了,但是有没有更好的解决方案而不是更改生成的代码?
这是我写的野牛文件:
//
// 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 ...
答:
162赞
James McNellis
5/7/2010
#1
您可能在某处包含了定义名为 和 的宏的 。windows.h
max
min
您可以在 include 之前阻止它定义这些宏,也可以通过使用一组额外的括号来阻止宏调用:#define NOMINMAX
windows.h
column = (std::max)(1u, column + count);
28赞
Rob Kennedy
5/7/2010
#2
在包含任何标头之前,在源的顶部定义 NOMINMAX 符号。Visual C++ 将 和定义为 windows.h 中的某个位置的宏,它们会干扰您对相应标准函数的使用。min
max
#define NOMINMAX
评论