fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct IBase
  6. {
  7. virtual bool foo()const=0;
  8. };
  9.  
  10. struct IDer: IBase
  11. {
  12. virtual bool baz1()const=0;
  13. virtual bool baz2()const=0;
  14. };
  15.  
  16. struct Standart: IBase
  17. {
  18. virtual bool foo()const { cout<<"Standart:foo\n"; return false; }
  19. };
  20. struct Der: Standart
  21. {
  22. virtual bool baz2()const { cout<<"Der:baz2\n"; return false; }
  23. virtual bool baz1()const { cout<<"Der:baz1\n"; return false; }
  24. };
  25.  
  26. int main()
  27. {
  28. std::cout << "Hello, world!\n";
  29.  
  30. Der d;
  31.  
  32. //не работает потому что IDer не является частью иерархии Der
  33. //IDer& id = static_cast<IDer&>(d);
  34.  
  35.  
  36. IDer& id = reinterpret_cast<IDer&>(d);
  37.  
  38. id.baz1();
  39. id.baz2();
  40. id.foo();
  41. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Hello, world!
Der:baz2
Der:baz1
Standart:foo