fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6. public:
  7. virtual void print(){cout<<"Base virtual"<<endl;}
  8. void nonvirt_print(){cout<<"Base"<<endl;}
  9. };
  10.  
  11. class Derived : public Base
  12. {
  13. public:
  14. virtual void print() override {cout<<"Derived virtual"<<endl;}
  15. void nonvirt_print(){cout<<"Derived"<<endl;}
  16. };
  17.  
  18. void f(Base **base_arr) {
  19. base_arr[10]->nonvirt_print(); //base
  20. base_arr[10]->print(); //derived virtual
  21. }
  22.  
  23. int main() {
  24. Derived *derived_arr[100];
  25. for(int i=0;i<100;++i)
  26. derived_arr[i] = new Derived();
  27. f(reinterpret_cast<Base*>(derived_arr));
  28. return 0;
  29. }
Compilation error #stdin compilation error #stdout 0s 4400KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:27:4: error: cannot convert ‘Base*’ to ‘Base**’
  f(reinterpret_cast<Base*>(derived_arr));
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:18:15: note:   initializing argument 1 of ‘void f(Base**)’
 void f(Base **base_arr) {
        ~~~~~~~^~~~~~~~
stdout
Standard output is empty