fork download
  1. #include <iostream>
  2.  
  3. class base{
  4. public:
  5. virtual int first(int a) = 0;
  6. int final_result(int a) {
  7. return 3*first(a);
  8. }
  9. // virtual int multiply(int a, int b, int c) = 0;
  10.  
  11. };
  12.  
  13. class derived : public base {
  14. public:
  15. int first(int a) {
  16. return 2*a;
  17. }
  18. };
  19.  
  20. class another_derived : public base {
  21. public:
  22. int first(int a, int b) {
  23. return a + b;
  24. }
  25.  
  26. };
  27.  
  28. int main() {
  29.  
  30. derived d;
  31. std::cout << d.final_result(1) << "\n";
  32. another_derived d2; // doesn't work
  33. return 0;
  34. }
Compilation error #stdin compilation error #stdout 0.01s 5340KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:32:18: error: cannot declare variable ‘d2’ to be of abstract type ‘another_derived’
  another_derived d2; // doesn't work
                  ^~
prog.cpp:20:7: note:   because the following virtual functions are pure within ‘another_derived’:
 class another_derived : public base {
       ^~~~~~~~~~~~~~~
prog.cpp:5:14: note: 	‘virtual int base::first(int)’
  virtual int first(int a) = 0;
              ^~~~~
stdout
Standard output is empty