fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct IStr
  5. {
  6. virtual std::ostream& beginMessage() = 0;
  7. //virtual std::ostream& endMessage(std::ostream&) = 0;
  8. };
  9.  
  10. struct MyStr : public IStr
  11. {
  12. std::ostream& beginMessage() override { return std::cout; }
  13. static std::ostream& endMessage(std::ostream& ss) { return std::endl(ss); }
  14. };
  15.  
  16. int main() {
  17. IStr * pStr = new MyStr();
  18. pStr->beginMessage() << "Hello World!" << MyStr::endMessage;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Hello World!