fork download
  1. class BaseInterface {
  2. public:
  3. virtual void someMethod()=0;
  4. };
  5.  
  6. class Derived: public BaseInterface {
  7. public:
  8. virtual void someMethod1()=0;
  9. void someMethod()override;
  10. };
  11.  
  12. class ThirdClass {
  13. public:
  14. void demoMethod(BaseInterface&);
  15. void anotherMethod(Derived&);
  16. };
  17.  
  18. void ThirdClass::demoMethod(BaseInterface& obj) {
  19. auto buffer=dynamic_cast<Derived&>(obj);
  20. anotherMethod(buffer);
  21. }
  22.  
  23. int main() {}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'void ThirdClass::demoMethod(BaseInterface&)':
prog.cpp:19:43: error: cannot allocate an object of abstract type 'Derived'
     auto buffer=dynamic_cast<Derived&>(obj);
                                           ^
prog.cpp:6:7: note:   because the following virtual functions are pure within 'Derived':
 class Derived: public BaseInterface {
       ^
prog.cpp:8:22: note: 	virtual void Derived::someMethod1()
         virtual void someMethod1()=0;
                      ^
prog.cpp:19:10: error: cannot declare variable 'buffer' to be of abstract type 'Derived'
     auto buffer=dynamic_cast<Derived&>(obj);
          ^
stdout
Standard output is empty