vectorを使ってみる

#include <iostream>
#include <vector>

using namespace std;

class Foo {
public:
  Foo() {
    cout << "new:" << this << endl;
  }

  Foo(const Foo &foo) {
    cout << "copy:" << this << endl;
  }

  Foo &operator=(Foo foo) {
    cout << "=:" << this << endl;
    return *this;
  }

  ~Foo() {
    cout << "delete:" << this << endl;
  }
};

int main() {
  Foo foo;
  vector<Foo> v;

  v.push_back(foo);
  v.push_back(foo);

  return 0;
}


new:0x22ccc0
copy:0x700278
copy:0x700288
copy:0x700289
delete:0x700278
delete:0x700288
delete:0x700289
delete:0x22ccc0
ふむふむ。