2008-05-29から1日間の記事一覧

vectorを使ってみる

C++

#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() </vector></iostream>…

vectorを使ってみる: ポインタにしてみる

C++

#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() </vector></iostream>…

vectorを配列にしてみる

C++

#include <iostream> #include <vector> using namespace std; void puts_array(int *p, int len) { for (int i = 0; i < len; i++) { cout << p[i] << endl; } } int main() { vector<int> v; for (int i = 0; i < 10; i++) { v.push_back(i); } puts_array(&v[0], v.size()); retu</int></vector></iostream>…