Expected unqualified identifier to a numeric constant

template <int K> class Wrap { // stuffs }; 

What is wrong if I create a template, for example Wrap < 5>4 > p; ? I get the expected unqualified identifier before a numeric constant . How to fix it?

+4
source share
3 answers

What is wrong if I create a template, for example Wrap < 5>4 > p; ?

This should be intuitively obvious just by looking at the statement: it confuses even for people! The compiler is not able to handle the double value > here: does that mean more? Does this mean "close the list of template arguments"? It turns out that this means that both the one and the other, and the compiler has no hint as to which sense to apply where. Both methods are technically sound.

+7
source

Change Wrap < 5>4 > p; on Wrap < (5>4) > p;

The first one > taken to be the end of the argument list of the template, and not more than the >

ISO C ++ [14.2 / 3]

When parsing the template identifier, the first non-nested > taken as the end of the template argument list, rather than a larger operator.

+12
source

ambiguity. Use Wrap <(5> 4)> instead.

+2
source

All Articles