Bob*_*mer 10 c++ templates template-templates visual-c++ c++11
以下是我的问题的SSCCE示例:
// 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;
}
Run Code Online (Sandbox Code Playgroud)
[ 编辑:LibraryT<MyEnum::Enum, MyEnumTemplate>改为LibraryT<typename 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'
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以像我的代码一样制作MSVC++编译器[ 编辑:MSVC++ 11编译器(VS 2012)]?通过一些添加规范或不同的方法?
硬编码枚举类型是一些整数类型(基础类型).那没问题.但是我的库正在使用积分而不是枚举类型(不受欢迎,但正常工作)
// 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;
}
Run Code Online (Sandbox Code Playgroud)
这是 Visual C++ 编译器中的一个已知错误。有关详细信息,请参阅 Microsoft Connect 上的以下错误(重现略有不同,但问题实际上是相同的):
推荐的解决方法是对模板模板参数的模板参数使用整数类型,这就是您在“可能的(但不合需要的)解决方案”中所做的。
| 归档时间: |
|
| 查看次数: |
711 次 |
| 最近记录: |