Advertisement
quark_zju

Untitled

Aug 24th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <vector>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. class A {
  7. public:
  8.   A () { printf(" + %x\n", this); }
  9.   virtual ~A () { printf(" - %x\n", this); };
  10.   A(const A& rhs) { printf(" = %x -> %x\n", &rhs, this); };
  11.  
  12. };
  13.  
  14. int main(int argc, char const* argv[])
  15. {
  16.   vector<A> a;
  17.  
  18.   for (int i = 0; i < 5; i++) {
  19.     printf("push_back #%d\n", i);
  20.     a.push_back(A());
  21.     printf("vector base = %x\n", &a[0]);
  22.   }
  23.  
  24.   return 0;
  25. }
  26.  
  27. /*
  28. push_back #0
  29.  + be763130
  30.  = be763130 -> 1731010
  31.  - be763130
  32. vector base = 1731010
  33. push_back #1
  34.  + be763130
  35.  = be763130 -> 1731038
  36.  = 1731010 -> 1731030
  37.  - 1731010
  38.  - be763130
  39. vector base = 1731030
  40. push_back #2
  41.  + be763130
  42.  = be763130 -> 1731060
  43.  = 1731030 -> 1731050
  44.  = 1731038 -> 1731058
  45.  - 1731030
  46.  - 1731038
  47.  - be763130
  48. vector base = 1731050
  49. push_back #3
  50.  + be763130
  51.  = be763130 -> 1731068
  52.  - be763130
  53. vector base = 1731050
  54. push_back #4
  55.  + be763130
  56.  = be763130 -> 17310a0
  57.  = 1731050 -> 1731080
  58.  = 1731058 -> 1731088
  59.  = 1731060 -> 1731090
  60.  = 1731068 -> 1731098
  61.  - 1731050
  62.  - 1731058
  63.  - 1731060
  64.  - 1731068
  65.  - be763130
  66. vector base = 1731080
  67.  - 1731080
  68.  - 1731088
  69.  - 1731090
  70.  - 1731098
  71.  - 17310a0
  72. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement