fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. class String {
  5. char * text;
  6. public:
  7. String( char * str );
  8. ~String();
  9. void printStr(){cout<<text<<endl;}
  10. };
  11. String::String( char * str ) {
  12. cout<<"enter 'String::String', str=>"<<str<<endl;
  13. text = new char[strlen(str)+1];
  14. strcpy( text, str );
  15. }
  16. String::~String() {
  17. cout<<"enter 'String::~String', text=>"<<(void*)text<<endl;
  18. //delete[]text;
  19. }
  20.  
  21. int main() {
  22. String str1("abcdef12345");
  23. String str2(str1);
  24. str1.printStr();
  25. str2.printStr();
  26. cout<<"ending main!"<<endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 2864KB
stdin
Standard input is empty
stdout
enter 'String::String', str=>abcdef12345
abcdef12345
abcdef12345
ending main!
enter 'String::~String', text=>0x9995008
enter 'String::~String', text=>0x9995008