fork(1) download
  1. #include <iostream>
  2.  
  3. using std::cout;
  4.  
  5. struct A
  6. {
  7. int a;
  8. char b;
  9. A(){ a = 4; }
  10. };
  11.  
  12. struct B
  13. {
  14. int c;
  15. B(){ c = 5; }
  16. };
  17.  
  18. A *a = new A;
  19. B *b = new B;
  20.  
  21. int main()
  22. {
  23. a = static_cast<A*>(b);
  24. cout << a -> a; //5
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:26: error: invalid static_cast from type ‘B*’ to type ‘A*’
     a = static_cast<A*>(b); 
                          ^
stdout
Standard output is empty