Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
When i try to compile the following code in VS 2012 i get errors on the Consumer class's typedef lines starting with:
error C2143: syntax error : missing ';' before '<'
Is this a problem with the compiler or is the code no longer valid c++? (The project it is extracted from certainly used to build without problems on older versions of VS - and gcc iirc - but that was about 10 years ago!)
struct TypeProvider
{
template<class T> struct Container
{
typedef vector<T> type;
};
};
template<class Provider>
class Consumer
{
typedef typename Provider::Container<int>::type intContainer;
typedef typename Provider::Container<double>::type doubleContainer;
};
There is a workaround for it but i just wonder if it should be required:
struct TypeProvider
{
template<typename T> struct Container { typedef vector<T> type; };
};
template<template<class T> class Container, class Obj>
struct Type
{
typedef typename Container<Obj>::type type;
};
template<typename Provider>
class TypeConsumer
{
typedef typename Type<Provider::Container, int>::type intContainer;
typedef typename Type<Provider::Container, double>::type doubleContainer;
};
You need to help the compiler know that Container
is a template:
template<class Provider>
class Consumer
{
typedef typename Provider:: template Container<int>::type intContainer;
typedef typename Provider:: template Container<double>::type doubleContainer;
};
This is very well explained in the accepted answer to this SO post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With