user1899020
user1899020

Reputation: 13575

Define a type of local class in a class template

Assume class Data has a local class template Element<i>, the following code has a compilation error. Code seems simple, but what is wrong?

template<unsigned i, class Data>
class A
{
public:
    typedef typename Data::Element<i> ElementTy; // compilation error: token error
};

Upvotes: 0

Views: 30

Answers (1)

Jesse Good
Jesse Good

Reputation: 52365

You need the template keyword:

typedef typename Data::template Element<i> ElementTy;

This tells the compiler that the name following is a template.

Upvotes: 1

Related Questions