user1403546
user1403546

Reputation: 1749

C++: enum type as template argument - global scope

I've a this situation:

template<typename myEnumType>
int foo(const myEnumType & shortest_paths_algorithm)
{
    ...
}

int main()
{
    myEnumType enum_type_istance;
    int a = foo(enum_type_istance)
}

if I declare

typedef enum {AAA, BBB} myEnumType;

before the function declaration everything is ok. While, if I write the above line before creating enum_type_istance variable, get the error

no matching function for call to ‘foo(main()::myEnumType&)’ candidate is: template int foo(const myEnumType&)

why??? how can I type-define inside the main? thank you!

Upvotes: 3

Views: 373

Answers (1)

Shoe
Shoe

Reputation: 76240

You are using C++ prior to C++11, which does not allow "local" types to be used in template arguments. This feature has been, luckily, introduced in C++11. As you can see it compiles just fine with the -std=c++11 flag, while it fails without.

Upvotes: 4

Related Questions