请考虑以下代码:

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

其他提示

我认为它与某种方式有关,因为Visual C ++在那一点上不知道指向成员的指针的大小。例如,检查缺陷报告(这里是指向成员变量的指针的另一个问题)。我认为您发现了另外一个Visual C ++错误,应该将其报告给connect.microsoft.com。

我偶然发现了同样的问题。 VC ++中对指针到成员模板参数的支持仍然有限(请参阅错误报告

在我的情况下,我可以使用模板函数i.s.o来解决它。模板类:

template< typename Class > struct CMemberDumper {
    Class& object;
    template< typename M > void visit_member( M C::*pm ) {
       std::cout << object.*pm;
    }
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top