fork(2) download
  1. #include <cassert>
  2. #ifndef NDEBUG
  3. #include <typeinfo>
  4. #endif
  5.  
  6. class shape
  7. {
  8. public:
  9. virtual ~shape() { }
  10.  
  11. shape* clone() const
  12. {
  13. shape* const p = do_clone();
  14. assert(p && "do_clone must not return a null pointer");
  15. assert(
  16. typeid(*p) == typeid(*this)
  17. && "do_clone must return a pointer to an object of the same type"
  18. );
  19. return p;
  20. }
  21.  
  22. private:
  23. virtual shape* do_clone() const = 0;
  24. };
  25.  
  26. template<class D>
  27. class cloneable_shape : public shape
  28. {
  29. private:
  30. virtual cloneable_shape* do_clone() const
  31. {
  32. return new D(static_cast<D const&>(*this));
  33. }
  34. };
  35.  
  36. class triangle : public cloneable_shape<triangle>
  37. {
  38. };
  39.  
  40. class square : public cloneable_shape<square>
  41. {
  42. };
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i486-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty