我无法访问指向成员的指针。为什么?
-
05-07-2019 - |
题
请考虑以下代码:
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
为什么编译器会生成错误? (VS2008)
新强>
我已将此错误发布到 connect.microsoft.com 一>
解决方案 2
这是错误
其他提示
我偶然发现了同样的问题。 VC ++中对指针到成员模板参数的支持仍然有限(请参阅错误报告)
在我的情况下,我可以使用模板函数i.s.o来解决它。模板类:
template< typename Class > struct CMemberDumper {
Class& object;
template< typename M > void visit_member( M C::*pm ) {
std::cout << object.*pm;
}
};
不隶属于 StackOverflow