fork(4) download
  1. #include <iostream>
  2.  
  3. struct Base
  4. {
  5. virtual void foo() const = 0;
  6. };
  7.  
  8. void Base::foo() const
  9. {
  10. std::cout << "Base!\n";
  11. }
  12.  
  13. struct Derived : Base
  14. {
  15. // Uncomment following line to remove error:
  16. //virtual void foo() const override { std::cout << "Derived\n"; Base::foo(); }
  17. };
  18.  
  19. int main()
  20. {
  21. Derived d;
  22. d.foo();
  23. }
Compilation error #stdin compilation error #stdout 0s 3340KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:21:11: error: cannot declare variable ‘d’ to be of abstract type ‘Derived’
   Derived d;
           ^
prog.cpp:13:8: note:   because the following virtual functions are pure within ‘Derived’:
 struct Derived : Base
        ^
prog.cpp:8:6: note: 	virtual void Base::foo() const
 void Base::foo() const
      ^
stdout
Standard output is empty