4

I am looking at C++ code that looks like this :

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

What is the int A::* construct? What requirement does it impose on the type A?

Thanks a lot!!

ildjarn
  • 62,044
  • 9
  • 127
  • 211
MK.
  • 3,907
  • 5
  • 34
  • 46
  • Here is a nice long SO thread on this exact topic: http://stackoverflow.com/questions/670734/c-pointer-to-class-data-member – kqnr Apr 10 '11 at 07:04

1 Answers1

3

int A::* is a pointer to an int data member of type A. E.g., given the types:

struct Foo { int i; };
struct Bar { double d; };
  • int Foo::* is a pointer to an int data member of type Foo, whose only valid values are null and the address of Foo::i
  • int Bar::* is a pointer to an int data member of type Bar, whose only valid value is null, as Bar contains no int data members

The only requirement imposed on type A is that it is not a primitive type, as primitive types obviously cannot have data members.

ildjarn
  • 62,044
  • 9
  • 127
  • 211