fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class String {
  5. public:
  6. String(const char* str) : data(str) {}
  7. ~String()
  8. {
  9. cout << "~String()." << endl;
  10. }
  11.  
  12. friend ostream& operator<<(ostream& stream, const String& s);
  13.  
  14. private:
  15. string data;
  16. };
  17.  
  18. ostream& operator<<(ostream& stream, const String& s)
  19. {
  20. return stream << s.data << endl;
  21. }
  22.  
  23. void printPointer(const String* pointer)
  24. {
  25. cout << *pointer << endl;
  26. cout << "End of printPointer" << endl;
  27. }
  28.  
  29. const String* func(const String& s1)
  30. {
  31. return &s1;
  32. }
  33.  
  34. int main()
  35. {
  36. printPointer(func("Hello, World!!!"));
  37. cout << "End of main()." << endl;
  38. }
  39.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Hello, World!!!

End of printPointer
~String().
End of main().