C++ 使用引用模板参数的部分专门化在VS2005中编译失败
我的代码可以归结为以下几点:C++ 使用引用模板参数的部分专门化在VS2005中编译失败,c++,templates,visual-studio-2005,compiler-errors,partial-specialization,C++,Templates,Visual Studio 2005,Compiler Errors,Partial Specialization,我的代码可以归结为以下几点: template <typename T> struct Foo {}; template <typename T, const Foo<T>& I> struct FooBar {}; //////// template <typename T> struct Baz {}; template <typename T, const Foo<T>& I> struct Ba
template <typename T> struct Foo {};
template <typename T, const Foo<T>& I> struct FooBar {};
////////
template <typename T> struct Baz {};
template <typename T, const Foo<T>& I>
struct Baz< FooBar<T,I> >
{
static void func(FooBar<T,I>& value);
};
////////
struct MyStruct
{
static const Foo<float> s_floatFoo;
};
// Elsewhere: const Foo<float> MyStruct::s_floatFoo;
void callBaz()
{
typedef FooBar<float, MyStruct::s_floatFoo> FloatFooBar;
FloatFooBar myFloatFooBar;
Baz<FloatFooBar>::func(myFloatFooBar);
}
GCC和VS2005都很高兴
发生什么事了?这是VS2005处理的与GCC不同的某种微妙的模板替换失败,还是编译器错误
(最奇怪的是:今天早上早些时候,我以为我在VS2005中使用了上述代码。但那是在我早上喝咖啡之前。我现在不完全确定我是否患有某种咖啡因渴求诱发的谵妄…)对我来说,VS2005似乎使用了第一个模板规范
Baz
template <typename T> struct Baz {};
模板结构Baz{};
此结构确实不包含名为
func
的成员。VS2005似乎无法正确推断模板参数。代码似乎正常。看起来像是VS2005中的一个bug。代码是用Comeau online编译的,所以可能没问题,限制到VS2005是的,它看起来越来越像VS中的bug。
typedef FooBar<float, &MyStruct::s_floatFoo> FloatFooBar;
template <typename T> struct Baz {};