fork download
  1. #include <cstdlib>
  2.  
  3. struct Shape {};
  4. struct Rect : public Shape {};
  5. struct Elipse : public Shape {};
  6.  
  7. Shape* randomShape() { return (std::rand() % 2) ? new Rect() : new Elipse(); }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘Shape* randomShape()’:
prog.cpp:7:75: error: conditional expression between distinct pointer types ‘Rect*’ and ‘Elipse*’ lacks a cast
 Shape* randomShape() { return (std::rand() % 2) ? new Rect() : new Elipse(); }
                                                                           ^
prog.cpp:7:78: warning: control reaches end of non-void function [-Wreturn-type]
 Shape* randomShape() { return (std::rand() % 2) ? new Rect() : new Elipse(); }
                                                                              ^
stdout
Standard output is empty