fork download
  1. #include <iostream>
  2.  
  3. class MyLogger {
  4. public:
  5. MyLogger(std::ostream& logStream)
  6. : logStream_(logStream)
  7. {}
  8.  
  9. template<typename T>
  10. friend MyLogger& operator<<(MyLogger&, const T&);
  11. private:
  12. std::ostream& logStream_;
  13. };
  14.  
  15. template<typename T>
  16. MyLogger& operator<<(MyLogger& log, const T& value) {
  17. log.logStream_ << value;
  18. return log;
  19. }
  20.  
  21. int main() {
  22. MyLogger log(std::cout);
  23.  
  24. log << "Hello" << " World!";
  25. }
  26.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Hello World!