Search code examples
c++templatesvisual-c++language-lawyerfriend

MSVC 2008 error 'Type' is not a struct (although it is)


The following MWE compiles on gcc 4.8.2 but not on MSVC 2008 (company policy)

struct B
{
};

struct A
{
    typedef B Handler;
};

template<typename T>
struct Foo
{
    typedef typename T::Handler  Type;
};

template<typename T>
struct Bar
{
    friend struct Foo<T>::Type;     // MSVC 2008 does not like this
    typedef typename Foo<T>::Type   Foo;
};

int main() 
{
}

MSVC 2008 error

error C2649: 'Foo<T>::Type' : is not a 'struct'

Is this a compiler bug or am I doing something illegal here? More importantly is there a fix?


Solution

  • Remove the struct keyword and replace it with typename:

    template<typename T>
    struct Bar
    {
        friend typename Foo<T>::Type;     
        typedef typename Foo<T>::Type   Foo;
    };