小编sub*_*ubi的帖子

指向带有继承的重载成员函数的指针的非类型模板参数

背景

请考虑以下代码:

struct A { // a class we want to hide from the client code
  int f();
  int f(char);
  int g();
};

struct B : A {}; // the interface class

// client code:
//
// It's natural to assume a member function of T should have
// a type of int (T::*)(), right?
template <typename T, int (T::*)()> struct F {};

// compiles, of course
F<A, &A::g> {};

// doesn't compile, because &B::g is not of type `int …
Run Code Online (Sandbox Code Playgroud)

c++ templates pointer-to-member

11
推荐指数
1
解决办法
290
查看次数

标签 统计

c++ ×1

pointer-to-member ×1

templates ×1