fork download
  1.  
  2. #include <stdio.h>
  3.  
  4. struct A {
  5. void foo() {puts("Привет, я A.");}
  6. };
  7.  
  8. struct B {
  9. void bar() {puts("Здарово, я B.");}
  10. };
  11.  
  12. int main () {
  13. B * b = new B();
  14. void (A::*func)() = &A::foo;
  15. (((A*)(&b))->*func)();
  16. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
Привет, я A.