我无法访问指向成员的指针。为什么?
考虑以下代码:
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。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这与 Visual C++ 不知道此时指向成员的指针的大小有关。例如,检查此缺陷报告 (这里是指向成员变量的指针的另一个问题)。我认为您又发现了一个 Visual C++ 错误,应该将其报告给 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
我偶然发现了同样的问题。 VC++ 中对指向成员模板参数的支持仍然有限(请参阅错误报告) 。
就我而言,我可以通过使用模板函数 iso 模板类来解决它:
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: