相关疑难解决方法(0)

没有匹配的函数调用<anonymous enum>

鉴于:

template<typename T>
void f( T ) {
}

enum {    // if changed to "enum E" it compiles
  e
};

int main() {
  f( e ); // line 10
}
Run Code Online (Sandbox Code Playgroud)

我明白了:

foo.cpp: In function ‘int main()’:
foo.cpp:10: error: no matching function for call to ‘f(<anonymous enum>)’
Run Code Online (Sandbox Code Playgroud)

然而,如果enum声明被赋予一个名称,它就会编译.为什么它不能用于匿名枚举?理想情况下,我希望它能够将枚举值e提升为int实例化f(int).

c++ enums templates

10
推荐指数
2
解决办法
2228
查看次数

标签 统计

c++ ×1

enums ×1

templates ×1