Skip to content

Instantly share code, notes, and snippets.

@7shi
Created October 9, 2011 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/1273084 to your computer and use it in GitHub Desktop.
Save 7shi/1273084 to your computer and use it in GitHub Desktop.
staticの有無と関数ポインタ
#include <stdio.h>
struct Test1 {
int n;
Test1(int n) : n(n) {}
void show() {
printf("%d\n", n);
}
};
struct Test2 {
int n;
Test2(int n) : n(n) {}
void show() {
printf("%d\n", n);
}
};
struct Test3 {
static void show() {
printf("?\n");
}
};
void show() {
printf("!\n");
}
void call(void (*f)()) { f(); }
int main() {
Test1 t1(1);
Test2 t2(2);
auto f1 = &Test1::show;
auto f2 = &Test2::show;
auto f3 = &Test3::show;
auto f4 = &show;
(t1.*f1)();
(t2.*f2)();
(*f3)();
(*f4)();
call(f3);
call(f4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment