我正在学习SFINAE(替换失败不是)我在网站上找到了一个例子,
template<typename T>
class is_class {
typedef char yes[1];
typedef char no [2];
template<typename C> static yes& test(int C::*); // What is C::*?
template<typename C> static no& test(...);
public:
static bool const value = sizeof(test<T>(0)) == sizeof(yes);
};
Run Code Online (Sandbox Code Playgroud)
我int C::*在第5行发现了一个新的签名.起初我以为它是,operator*但我想这不是真的.请告诉我它是什么.
int C::*是指向C类型为的类成员的指针int.
例:
struct C
{
C () : a(0), b(0) {}
int a;
int b;
};
int main()
{
int C::*member1 = &C::a;
int C::*member2 = &C::b;
C c1;
c1.*member1 = 10; // Sets the value of c1.a to 10
c1.*member2 = 20; // Sets the value of c1.b to 20
}
Run Code Online (Sandbox Code Playgroud)