I can't figure out how to access the enum class enumerators, either as a returning value or just a value, from a templatized class. As you can see in the following example I'm totally clueless. I've googled over the error messages with no luck.
Glad if you point me out to the correct syntax.
First these are the errors:
$ g++ -Wall -std=c++11 -o main.out main.cpp
main.cpp:25:1: error: need ‘typename’ before ‘C::Values’ because ‘C’ is a dependent scope
C::Values C::Get() // <-- Error here ... ^ main.cpp: In function ‘int main()’: main.cpp:35:2: error: ‘template class C’ used without template parameters
C::Values values; // <-- ... and here
^
$
And this is the complete example so it can be tested:
template<int Val>
class C
{
public:
enum class Values{ one, two };
C();
Values Get();
private:
int val;
};
template<int Val>
C<Val>::C() : val{ Val } {}
template<int Val>
C<Val>::Values C<Val>::Get() // <-- Error here ...
{
return Values::one;
}
int main(void)
{
C<5> aVariable;
C::Values values; // <-- ... and here
return 0;
}
Thank your in advanced!!