【问题标题】:error: expected primary-expression before ‘...’ token on gcc错误:gcc 上的“...”标记之前的预期主表达式
【发布时间】:2021-10-11 12:40:41
【问题描述】:

我在 gcc 10.3 上遇到了这个编译错误:

<source>:15:22: error: expected primary-expression before '...' token
   15 |     void g() { a.f<Cs...>();}
      |                      ^~~
<source>:15:22: error: expected ';' before '...' token
   15 |     void g() { a.f<Cs...>();}
      |                      ^~~
      |                      ;

原来clang实际上告诉你出了什么问题:

<source>:15:18: error: use 'template' keyword to treat 'f' as a dependent template name
    void g() { a.f<Cs...>();}
                 ^
                 template 

here's a minimum reproductible example

template<typename ...Ts>
class A{
public:
    template<typename ...Cs>
    void f() {}
};

template<typename ...Ts>
class B{

    public:
    template<typename ...Cs>
    void g() { a.f<Cs...>();}

    private : 
    A<Ts...> a;
};

【问题讨论】:

  • 我认为这些是解决方案:CXX_STANDARD, CMAKE_CXX_STANDARD
  • 我已经在做:set_target_properties(chunk_manager PROPERTIES INTERFACE_COMPILE_FEATURES cxx_std_20)set_target_properties(chunk_manager PROPERTIES CXX_STANDARD 20)
  • 你做错了。日志文件显示: -- 构建类型:Debug -- CXX_STANDARD: 11。
  • 这实际上是依赖项(fmt 库)的日志。 -- CPM: chunk_manager: 添加包 fmt@8.0.1 (8.0.1 到 /home/runner/work/chunk_manager/chunk_manager/cpm_modules/fmt/b116ec18610f0c5e13500fecc7a23457fa963003) -- 模块支持被禁用。 -- 版本:8.0.1 -- 构建类型:Debug -- CXX_STANDARD: 11

标签: c++ linux compiler-errors g++


【解决方案1】:

解决方案是使用“模板”关键字将“f”视为依赖模板名称,如下所示:

template<typename ...Cs>
void g() { a.template f<Cs...>();}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-28
    • 2013-01-13
    • 2017-09-24
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多