Question

Consider the following code:

template<class T, class F>           struct X {};
template<class T, class F, T F::* m> struct Y {};

struct Foo {
    int member;
    typedef X<int, Foo>               x_type; // works well
    typedef Y<int, Foo, &Foo::member> y_type; // ERROR
};

typedef Y<int, Foo, &Foo::member> y_type2; // OK

Why does compiler generate error? (VS2008)


New

I have posted this bug to connect.microsoft.com.

Was it helpful?

Solution 2

This is a bug

OTHER TIPS

I think that it is related somehow with that Visual C++ don't know the size of pointer to member at that point. Check this defect report for instance (here is another problem with pointer to member variable). I think that you found one more Visual C++ bug and it should be reported to connect.microsoft.com.

I stumbled upon the same problem. The support for pointer-to-member template arguments is still limited in VC++ (see bug report).

In my case I could work around it by using a template function i.s.o. a template class:

template< typename Class > struct CMemberDumper {
    Class& object;
    template< typename M > void visit_member( M C::*pm ) {
       std::cout << object.*pm;
    }
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top