Skip to content

Instantly share code, notes, and snippets.

@kusano
Created April 21, 2015 13:16
Show Gist options
  • Save kusano/53f6e8f2ef0ff06e77e5 to your computer and use it in GitHub Desktop.
Save kusano/53f6e8f2ef0ff06e77e5 to your computer and use it in GitHub Desktop.
メンバ変数への汎用ポインタ
struct A {
int a;
};
int main()
{
A a;
int *p0 = &a.a; // OK
void *p1 = &a.a; // OK
int A::*p2 = &A::a; // OK
void A::*p3 = &A::a; // NG
void *p4 = (void *)&A::a; // NG
// エラー: invalid cast from type ‘int A::*’ to type ‘void*’
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment