Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected unqualified-id before numeric constant

Tags:

c++

templates

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

What is wrong if I instantiate the template like Wrap < 5>4 > p;? I get expected unqualified-id before numeric constant error. How to fix this?

like image 931
Mike Morum Avatar asked May 26 '11 18:05

Mike Morum


1 Answers

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

The first > encountered is taken as the end of the template argument list rather than greater than operator >

ISO C++ [14.2/3]

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

like image 73
Prasoon Saurav Avatar answered Nov 01 '22 22:11

Prasoon Saurav