fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6. public:
  7. virtual void Foo() = 0;
  8. };
  9.  
  10. class Derived
  11. : public Base
  12. {
  13. public:
  14. // void Foo() { } // Derived cannot be instantiated, it MUST define Foo()
  15. // OR its derived classes MUST define Foo(). The
  16. // method is NOT optional when you want to instantiate
  17. // the class
  18. };
  19.  
  20. int main() {
  21. // your code goes here
  22. Derived d;
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:10: error: cannot declare variable ‘d’ to be of abstract type ‘Derived’
  Derived d;
          ^
prog.cpp:10:7: note:   because the following virtual functions are pure within ‘Derived’:
 class Derived
       ^
prog.cpp:7:16: note: 	virtual void Base::Foo()
   virtual void Foo() = 0;
                ^
stdout
Standard output is empty