fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void messagebox(const char*) {
  6. cout << "messagebox()" << endl;
  7. }
  8.  
  9. struct tmp {
  10. tmp(const char* content) : content(content) { cout << "tmp c'tor" << endl; }
  11. ~tmp() { cout << "tmp d'tor" << endl; }
  12. const char* c_str() { return content.c_str(); }
  13. private:
  14. string content;
  15. };
  16.  
  17. struct ss {
  18. tmp str() { return tmp("test"); }
  19. };
  20.  
  21. int main() {
  22. ss s;
  23. const char* name = s.str().c_str();
  24. messagebox(name);
  25.  
  26. cout << endl << endl;
  27. messagebox(s.str().c_str());
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
tmp c'tor
tmp d'tor
messagebox()


tmp c'tor
messagebox()
tmp d'tor