是否指向成员特征或类似的东西?

Ale*_*tov 5 c++ templates pointer-to-member

根据我的其他问题.

请考虑以下代码

template<typename T, int N>
struct A {
  typedef T value_type; // save T to value_type
  static const int size = N; // save N to size
};
Run Code Online (Sandbox Code Playgroud)

看,我可以使用value_typesize作为模板参数.

typedef A<int, 2> A1;
typedef A<A1::value_type, A1::size + 3> A2;  // OK,  A2 is A<int,5>
Run Code Online (Sandbox Code Playgroud)

现在我想用指向成员的指针做同样的事情:

struct Foo {
    int m;
    int r;
};

template<int Foo::*Mem>
struct B {
   static int Foo::* const mp;
};

template<int Foo::*Mem>
int Foo::* const B<Mem>::mp = Mem; // Save pointer to member
Run Code Online (Sandbox Code Playgroud)

但我得到错误.

typedef B<&Foo::m> B1;
typedef B<B1::mp>  B2;  // DOES NOT WORK
Run Code Online (Sandbox Code Playgroud)

如何使最后一行工作?或者如何获得模拟结果?

注意.我知道它不起作用.不需要指向C++标准的链接.我需要解决方法.

Sam*_*ton 0

迈克是对的,它应该编译。这是VS的一个bug 。