fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. virtual int Afunc() { return 2; };
  7. int a;
  8. };
  9.  
  10. class B {
  11. public:
  12. virtual int Bfunc()
  13. {
  14. cout<<"this : "<<this<<endl;
  15. return 3;
  16. }
  17. int b;
  18. };
  19.  
  20. // C is a single inheritance class, derives only from A
  21. class C: public A {
  22. public:
  23. int Cfunc() { return 4; };
  24. int c;
  25. };
  26.  
  27. // D uses multiple inheritance
  28. class D: public A, public B {
  29. public:
  30. virtual int Dfunc()
  31. {
  32. cout<<"this : "<<this<<endl;
  33. return 5;
  34. }
  35. int d;
  36. };
  37.  
  38. int main() {
  39. // your code goes here
  40.  
  41. typedef int (D::*fptr)(void);
  42.  
  43. fptr bfunc;
  44. fptr dfunc;
  45.  
  46. bfunc=&D::Bfunc;
  47. dfunc=&D::Dfunc;
  48.  
  49. cout<<(reinterpret_cast<unsigned long long >(bfunc)&0xffffffffffffffff)<<endl;
  50. //cout<<(((void *)dfunc)&(0xffff0000))<<endl;
  51.  
  52. //(void*)(bfunc);
  53. return 0;
  54. }
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:49:52: error: invalid cast from type 'fptr {aka int (D::*)()}' to type 'long long unsigned int'
  cout<<(reinterpret_cast<unsigned long long >(bfunc)&0xffffffffffffffff)<<endl;
                                                    ^
stdout
Standard output is empty