这个模板函数的类型要求是什么

What are the requirements on type for this template function

本文关键字:类型 是什么 函数      更新时间:2023-10-16

我看到的C++代码如下:

template<class A>
bool foo(int A::*)
{ /*blah*/ }

什么是int A::*结构?它对A型有什么要求?

非常感谢!!

int A::*是指向A类型的int数据成员的指针。例如,给定类型:

struct Foo { int i; };
struct Bar { double d; };
  • int Foo::*是指向Foo类型的int数据成员的指针,其唯一有效值为null和Foo::i的地址
  • int Bar::*是指向Bar类型的int数据成员的指针,其唯一有效值为null,因为Bar不包含int数据成员

对类型A的唯一要求是它不是基元类型,因为基元类型显然不能有数据成员。