Reputation: 12998
//more code omitted that is not relevant, the IF template is not completely shown here
template <bool condition, typename ThenType, typename ElseType>
struct IF {
typedef typename ChooseSelector<condition>::RETURN Selector;
};
template <bool condition>
struct ChooseSelector {
typedef SelectThen RETURN;
};
template <>
struct ChooseSelector<false> {
typedef SelectElse RETURN;
};
//SelectElse and SelectThen omitted
I get Expected nested-name-specifier before ‘ChooseSelector’
. According to the often linked C++ typename description and if I get it correctly, typename
is needed here. If I remove typename from the IF template, I still get the same error, so I am a little confused what is actually causing the error. I read many answers that suggest that removing typename fixes the problem, but that is not the case in this case. What am I missing?
The error comes from g++ on Linux, VS10 throws an error as well.
Upvotes: 2
Views: 276
Reputation: 91270
Put your IF template after the ChooseSelector template.
When compiling the IF template, ChooseSelector need to exist as a template, you're using ChooseSelector<condition>
which is parsed first pass. The typename
is needed to tell the compiler that RETURN
, which is fully evaluated on instantiation when specializations are known, should be considered a type for the purpose of first pass.
Upvotes: 2