C :枚举类型作为模板参数 - 全局范围
C++: enum type as template argument - global scope
我已经有这种情况:
template<typename myEnumType>
int foo(const myEnumType & shortest_paths_algorithm)
{
...
}
int main()
{
myEnumType enum_type_istance;
int a = foo(enum_type_istance)
}
如果我声明
typedef enum {AAA, BBB} myEnumType;
在函数声明之前,一切正常。同时,如果我在创建enum_type_istance变量之前写上述行,请获取错误
无匹配函数呼叫" foo(main():: myenumtype&amp;)" 候选人是:template int foo(const myenumtype&amp;)
为什么???如何在主内输入定义?谢谢!
您在C 11之前使用的是C ,这不允许在模板参数中使用"本地"类型。幸运的是,此功能是在C 11中引入的。如您所见,它可以使用-std=c++11
标志来编译它,而它会在没有的情况下进行。
相关文章:
- 带参数的数据结构的全局声明
- 全局函数参数
- 包括一个类来定义全局变量参数 c++ :(
- 使用全局 std::array 引用作为模板参数时如何简化参数?
- 是否可以基于类模板的参数调用类方法和全局方法
- 没有参数的递归,也没有静态或全局变量
- 运算符<<依赖于参数的查找不在全局命名空间中查找
- 有什么理由C++ 11+ std::mutex 应该声明为全局变量,而不是作为函数参数传递到 std::thread 中
- 升压安装:缺少参数全局设定
- 无全局变量或功能参数的递归调用
- 是否可以通过全局变量定义具有可变参数数的函数中的参数数量
- 参数和全局变量,菜单程序
- 适用于全局模板运算符指定模板参数的适当语法
- 全局变量作为默认参数
- 如何在野牛C 中制作全局参数
- 将功能指针及其参数作为推力::元组传递给全局函数
- 提升预定义为带有参数的全局 lambda 的变体访问者
- C :枚举类型作为模板参数 - 全局范围
- 使用全局变量作为在其他源文件中分配的函数的参数
- C/C++,在使用全局参数或传递参数之间进行选择