I have code that boils down to the following:
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);
}
This compiles successfully under GCC, however, under VS2005, I get:
error C2039: 'func' : is not a member of 'Baz<T>'
with
[
T=FloatFooBar
]
error C3861: 'func': identifier not found
However, if I change const Foo<T>& I
to const Foo<T>* I
(passing I
by pointer rather than by reference), and defining FloatFooBar
as:
typedef FooBar<float, &MyStruct::s_floatFoo> FloatFooBar;
Both GCC and VS2005 are happy.
What's going on? Is this some kind of subtle template substitution failure that VS2005 is handling differently to GCC, or a compiler bug?
(The strangest thing: I thought I had the above code working in VS2005 earlier this morning. But that was before my morning coffee. I'm now not entirely certain I wasn't under some sort of caffeine-craving-induced delirium...)