2009-06-03から1日間の記事一覧

null値のshared_ptr

C++

melponnさんにコメントをいただいたので早速使ってみた。 #include <iostream> #include <string> #include <vector> #include <memory> using namespace std; using namespace std::tr1; int main() { typedef shared_ptr<string> strp; vector<strp> v; v.push_back(strp(new string("foo"))); v.push_back(</strp></string></memory></vector></string></iostream>…

null値のshared_ptr その2

C++

http://kabuki.spring8.or.jp/Members/matusita/forums/cpp-tips/document.2005-10-09.6758608810 「shared_ptr(static_cast(0))」じゃなくて、デフォルトコンストラクタで生成すれば良かったのか・・・。 「if (p)」は間違い? 追記 ひょっとして「shared_ptr:…

scoped_ptrでメンバ変数

C++

なんかもう「Boost使っちゃいYo!」って気がしてきた。 #include <iostream> #include <string> #include <boost/scoped_ptr.hpp> using namespace std; class Child { public: Child() { cout << "Child::new(): " << this << endl; } ~Child() { cout << "Child#delete(): " << this << endl; } }; c</boost/scoped_ptr.hpp></string></iostream>…

_Bool_type

C++

_Bool_typeが気になったので少し調査。 #include <iostream> using namespace std; class TrueFalse { bool r_; public: TrueFalse(bool r) : r_(r) {}; operator std::_Bool_type() const { return r_ ? _CONVERTIBLE_TO_TRUE : 0; } }; void print_bool(TrueFalse& t</iostream>…