我有一个这样的情况:
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&)”匹配的函数 候选项为:模板int foo(const myEnumType&)
为什么???我如何在主函数内定义类型? 谢谢!
int
从不是本地类型。本地类型是在函数内定义的类型。typedef
非常透明,因此它(似乎)不关心您使用typedef
还是所引用的类型。 - dyp