fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct Base
  4. {
  5. virtual ~Base()
  6. {};
  7. };
  8. struct Derived : public virtual Base {};
  9.  
  10. int main()
  11. {
  12. Base* b = new Derived;
  13. #if 0
  14. Derived* d = dynamic_cast<Derived*>(b);
  15. #else
  16. Derived* d = static_cast<Derived*>(b);
  17. #endif
  18. cout << d << endl;
  19. }
Compilation error #stdin compilation error #stdout 0s 2984KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:39: error: cannot convert from base ‘Base’ to derived type ‘Derived’ via virtual base ‘Base’
stdout
Standard output is empty