代码之家  ›  专栏  ›  技术社区  ›  Alex

Cygwin中的错误似乎与描述不匹配

  •  1
  • Alex  · 技术社区  · 10 月前

    错误显示:

    error: expected ',' or '...' before '(' token
     int exec_wait(const std::string& path, std::string& stdout, ...)
                                                         ^
    

    任何人都知道它为什么抱怨 ( 指向时标记 s ?我甚至不知道从哪里开始。。。

    该错误几乎在没有其他代码的情况下发生。最简单的例子是:

    #include <string>
    
    int exec_wait(const std::string& path, std::string& stdout, ...)
    {
    }
    
    1 回复  |  直到 10 月前
        1
  •  1
  •   Yksisarvinen    10 月前

    stdout 是标准库中定义的宏: https://en.cppreference.com/w/cpp/io/c/std_streams .定义见 cstdio ,但允许使用任何标准库标头 #include 任何其他标准库标头,在这种情况下,它似乎 string 包括 cstdio .

    回答标题问题:编译器在预处理后看到代码(因此所有宏都被展开)。定义 stdout 取决于编译器,但可能类似 (stuff_here) ,因此编译器可以看到 int exec_wait(const std::string& path, std::string& (stuff_here), ...) 以及在这方面的错误。

    解决方案是为你的论点选择一个不同的名称。

    以后,请避免使用此列表中的任何名称: https://en.cppreference.com/w/cpp/symbol_index/macro (请注意,它们大多为大写或以下划线开头,因此不难避免)。