コード
は私の問題のSSCCE例です。テンプレートテンプレートクラスはMSVC++コンパイラに失敗します。ここではC3201
// My Library, which I want to take in the user's enum and a template class which they put per-enum specialized code
template <typename TEnum, template <TEnum> class EnumStruct>
struct LibraryT { /* Library stuff */ };
// User Defined Enum and Associated Template (which gets specialized later)
namespace MyEnum {
enum Enum {
Value1 /*, ... */
};
};
template <MyEnum::Enum>
struct MyEnumTemplate {};
template <>
struct MyEnumTemplate<MyEnum::Value1> { /* specialized code here */ };
// Then the user wants to use the library:
typedef LibraryT<MyEnum::Enum, MyEnumTemplate> MyLibrary;
int main() {
MyLibrary library;
}
[EDIT:LibraryT<typename MyEnum::Enum, MyEnumTemplate>
にLibraryT<MyEnum::Enum, MyEnumTemplate>
を変更すると効果がありません]
エラー
私が望む機能列挙型とその列挙型に特化したクラスに基づいてライブラリを作成する能力です。上記は私の最初の試みです。私はそれが100%C++であると信じています。そして、GCCは私をバックアップし、それがすべて動作すると言います。しかし、私はそれがMSVC++コンパイラでコンパイルしたい、それが拒否する:
error C3201: the template parameter list for class template 'MyEnumTemplate'
does not match the template parameter list for template parameter 'EnumStruct'
質問
私はMSVC++コンパイラを作ることができるいくつかの方法があります[EDIT:MSVC++ 11コンパイラ(2012 VS)]私のコードのように?いくつかの追加仕様または異なるアプローチのどちらかによって?
ソリューションの可能性(望ましくない)
ハードコード列挙型は、いくつかの整数型(基本となる型)をするように。その後、問題はありません。しかし、その後、私のライブラリではなく、列挙型(望ましくないが、作業)
// My Library, which I want to take in the user's enum and a template class which they put per-enum specialized code
typedef unsigned long IntegralType; // **ADDED**
template <template <IntegralType> class EnumStruct> // **CHANGED**
struct LibraryT { /* Library stuff */ };
// User Defined Enum and Associated Template (which gets specialized later)
namespace MyEnum {
enum Enum {
Value1 /*, ... */
};
};
template <IntegralType> // **CHANGED**
struct MyEnumTemplate {};
template <>
struct MyEnumTemplate<MyEnum::Value1> {};
// Then the user wants to use the library:
typedef LibraryT<MyEnumTemplate> MyLibrary; // **CHANGED**
int main() {
MyLibrary library;
}
結局のところ、VC++ 2010または2012ですか? – ildjarn
@idjarn最新のもの:MSVC++ 11コンパイラ(VS 2012に含まれています) –
@ahendersonこの場合、 'typename'部分はオプションで、それを加えても違いはありません –