Say SomeStruct is defined as:
struct SomeStruct {
int member;
};
What does these means?
&SomeStruct::memberint SomeStruct::*
I encounter this, tried to output its type info but still cannot figure out the meaning. Below is a working example:
#include <iostream>
#include <typeinfo>
using namespace std;
struct SomeStruct {
int member;
};
int main(int argc, const char *argv[])
{
cout << typeid(&SomeStruct::member).name() << endl;
cout << typeid(int SomeStruct::*).name() << endl;
return 0;
}
Compiled by i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664) on my MBP, the output is:
M10SomeStructi
M10SomeStructi
int SomeStruct::*is called a “pointer to member”, in this case, a pointer to a member ofSomeStruct. This is NOT strictly a pointer to a member function (although this is the most common use of this syntax).&SomeStruct::memberis a reference to themembermember ofSomeStruct.See this related question
If you’d like some more complete information on the topic, here’s a decent article on the topic.
And, the obligatory section on the topic in the C++ FAQ lite.