fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <cstdlib>
  4.  
  5. struct test {
  6. int x;
  7. std::string s;
  8.  
  9. void* operator new( std::size_t size) {
  10. char * p = (char*) malloc( size );
  11. for ( std::size_t i = 0; i < size; ++i ) {
  12. p[i] = 0xba;
  13. }
  14. return p;
  15. }
  16. void operator delete(void* p) {
  17. free(p);
  18. }
  19. };
  20.  
  21. void f() {
  22. test t;
  23. std::cout << t.x << std::endl;
  24. t.x = 5;
  25. }
  26.  
  27. void g() {
  28. test t = test();
  29. std::cout << t.x << std::endl;
  30. t.x = 5;
  31. }
  32.  
  33. int main() {
  34. std::auto_ptr<test> p1( new test );
  35. std::cout << std::hex << p1->x << std::endl;
  36.  
  37. std::auto_ptr<test> p2( new test() );
  38. std::cout << std::hex << p2->x << std::endl;
  39.  
  40. f(); f();
  41. g(); g();
  42. }
  43.  
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
babababa
babababa
babababa
5
0
0