fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Test
  5. {
  6. public:
  7. Test(string s)
  8. {
  9. str = s;
  10. cout<<"Test creat\n";
  11. }
  12. ~Test()
  13. {
  14. cout<<"Test delete:"<<str<<endl;
  15. }
  16. string& getStr()
  17. {
  18. return str;
  19. }
  20. void setStr(string s)
  21. {
  22. str = s;
  23. }
  24. void print()
  25. {
  26. cout<<str<<endl;
  27. }
  28. private:
  29. string str;
  30. };
  31.  
  32.  
  33. int main()
  34. {
  35. auto_ptr<Test> ptest(new Test("123"));
  36. ptest->setStr("hello ");
  37. ptest->print();
  38. ptest.get()->print();
  39. ptest->getStr() += "world !";
  40. (*ptest).print();
  41. ptest.reset(new Test("123"));
  42. ptest->print();
  43. return 0;
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:35:5: error: ‘auto_ptr’ was not declared in this scope
     auto_ptr<Test> ptest(new Test("123"));
     ^~~~~~~~
prog.cpp:35:18: error: expected primary-expression before ‘>’ token
     auto_ptr<Test> ptest(new Test("123"));
                  ^
prog.cpp:35:41: error: ‘ptest’ was not declared in this scope
     auto_ptr<Test> ptest(new Test("123"));
                                         ^
stdout
Standard output is empty