VS 2012で次のコードをコンパイルしようとすると、Consumerクラスのtypedef行で次の文字で始まるエラーが発生します。
error C2143: syntax error : missing ';' before '<'
これはコンパイラの問題ですか、それともコードは有効ではなくなったc ++ですか?(それが抽出されたプロジェクトは、確かに古いバージョンのVS(およびgcc iirc)で問題なくビルドするために使用されましたが、それは約10年前のことです!)
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;
};
それには回避策がありますが、それが必要かどうか疑問に思います:
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;
};