fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. class First
  5. {
  6. public:
  7. First():text("Hi im first!!!"){;}
  8. void virtual WhoIsWho(){cout<<"its must be first "<<text<<endl;}
  9. protected:
  10. char * text;
  11. };
  12. class Second:public First
  13. {
  14. public:
  15. Second(){text = "Hi im second";}
  16. void WhoIsWho(){cout<<"its must be second "<<text<<endl;}
  17. };
  18.  
  19. int main()
  20. {
  21. Second A;
  22. First B, *C(&A);
  23. B=C[0];
  24. C->WhoIsWho();
  25. B.WhoIsWho();
  26. memcpy(&B,C,sizeof(B));
  27. B.WhoIsWho();
  28. return 0;
  29. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
its must be second Hi im second
its must be first Hi im second
its must be first Hi im second