I can not get access to pointer to member. Why?
Consider the following code:
template<class T, class F> struct X {};
template<cl开发者_Python百科ass 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.
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.
This is a bug
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;
}
};
精彩评论