fork download
  1. #include <iostream>
  2.  
  3. struct Test {
  4. std::string name;
  5. std::string toString() const { return name; }
  6. };
  7.  
  8. std::ostream & operator <<(std::ostream & o, const Test & t) {
  9. return o << t.toString();
  10. }
  11. std::ostream & operator <<(std::ostream & o, const Test * t) {
  12. return o << t->toString();
  13. }
  14.  
  15. int main() {
  16. Test t1;
  17. t1.name = "foo";
  18.  
  19. Test * t2 = new Test();
  20. t2->name = "foo";
  21.  
  22. std::cout << t1 << std::endl;
  23. std::cout << t2 << std::endl;
  24. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
foo
foo