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:0012FF57
delete:0012FF57
ふむふむ。