• <legend id='HXBvY'><style id='HXBvY'><dir id='HXBvY'><q id='HXBvY'></q></dir></style></legend>
      <tfoot id='HXBvY'></tfoot>

      <small id='HXBvY'></small><noframes id='HXBvY'>

        • <bdo id='HXBvY'></bdo><ul id='HXBvY'></ul>
      1. <i id='HXBvY'><tr id='HXBvY'><dt id='HXBvY'><q id='HXBvY'><span id='HXBvY'><b id='HXBvY'><form id='HXBvY'><ins id='HXBvY'></ins><ul id='HXBvY'></ul><sub id='HXBvY'></sub></form><legend id='HXBvY'></legend><bdo id='HXBvY'><pre id='HXBvY'><center id='HXBvY'></center></pre></bdo></b><th id='HXBvY'></th></span></q></dt></tr></i><div id='HXBvY'><tfoot id='HXBvY'></tfoot><dl id='HXBvY'><fieldset id='HXBvY'></fieldset></dl></div>
      2. 调用 std::max 时出现问题

        时间:2023-07-01
          <i id='RgRKW'><tr id='RgRKW'><dt id='RgRKW'><q id='RgRKW'><span id='RgRKW'><b id='RgRKW'><form id='RgRKW'><ins id='RgRKW'></ins><ul id='RgRKW'></ul><sub id='RgRKW'></sub></form><legend id='RgRKW'></legend><bdo id='RgRKW'><pre id='RgRKW'><center id='RgRKW'></center></pre></bdo></b><th id='RgRKW'></th></span></q></dt></tr></i><div id='RgRKW'><tfoot id='RgRKW'></tfoot><dl id='RgRKW'><fieldset id='RgRKW'></fieldset></dl></div>

              • <bdo id='RgRKW'></bdo><ul id='RgRKW'></ul>

                <small id='RgRKW'></small><noframes id='RgRKW'>

                <tfoot id='RgRKW'></tfoot>

                    <tbody id='RgRKW'></tbody>
                  <legend id='RgRKW'><style id='RgRKW'><dir id='RgRKW'><q id='RgRKW'></q></dir></style></legend>
                  本文介绍了调用 std::max 时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

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

                  ...position.hh(83): error C2589: '(' : '::'右侧的非法标记
                  ...position.hh(83):错误 C2059:语法错误:'::'
                  ...position.hh(83): error C2589: '(' : '::'右侧的非法标记
                  ...position.hh(83):错误 C2059:语法错误:'::'

                  ...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 : '::'

                  对应的代码为:

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

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

                  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?

                  这是我写的野牛文件:

                  //
                  // 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,它定义了名为 maxmin 的宏.

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

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

                  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);
                  

                  这篇关于调用 std::max 时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么 Visual C++ 缺乏重构功能? 下一篇:从哪里获得 C++ 标准库的源代码?

                  相关文章

                1. <i id='GoMyt'><tr id='GoMyt'><dt id='GoMyt'><q id='GoMyt'><span id='GoMyt'><b id='GoMyt'><form id='GoMyt'><ins id='GoMyt'></ins><ul id='GoMyt'></ul><sub id='GoMyt'></sub></form><legend id='GoMyt'></legend><bdo id='GoMyt'><pre id='GoMyt'><center id='GoMyt'></center></pre></bdo></b><th id='GoMyt'></th></span></q></dt></tr></i><div id='GoMyt'><tfoot id='GoMyt'></tfoot><dl id='GoMyt'><fieldset id='GoMyt'></fieldset></dl></div>

                      <bdo id='GoMyt'></bdo><ul id='GoMyt'></ul>

                    <small id='GoMyt'></small><noframes id='GoMyt'>

                    1. <legend id='GoMyt'><style id='GoMyt'><dir id='GoMyt'><q id='GoMyt'></q></dir></style></legend>

                      <tfoot id='GoMyt'></tfoot>