Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "Class::*"

Tags:

c++

I am learning SFINAE(Substitution failure is not) I found an example of it in a site,

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);
};

I found a new signature, int C::* at a line 5. At first I thought it is operator* but I suppose it is not true. Please tell me what is it.

like image 345
mora Avatar asked Jun 23 '15 04:06

mora


1 Answers

int C::* is a pointer to a member of class C whose type is int.

Example:

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
}
like image 83
R Sahu Avatar answered Nov 01 '22 14:11

R Sahu