fork download
  1. #include <iostream>
  2.  
  3. struct IAudible {
  4. virtual void sound() const = 0;
  5. };
  6.  
  7. struct Explosion : public IAudible {
  8. virtual void sound() const override { std::cout << "Boom\n"; }
  9. };
  10.  
  11. struct Word : public IAudible {
  12. };
  13.  
  14. void announce(const IAudible& audible) {
  15. audible.sound();
  16. }
  17.  
  18. int main() {
  19. Explosion e;
  20. announce(e);
  21. Word w;
  22. announce(w);
  23. }
  24.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:21:14: error: cannot declare variable 'w' to be of abstract type 'Word'
         Word w;
              ^
prog.cpp:11:12: note:   because the following virtual functions are pure within 'Word':
     struct Word : public IAudible {
            ^
prog.cpp:4:22: note: 	virtual void IAudible::sound() const
         virtual void sound() const = 0;
                      ^
stdout
Standard output is empty