2008-12-22から1日間の記事一覧

C++0x explicit bool

C++

スマートポインタのようなクラスを作成する場合、if文でヌルポインタかどうか判定できるようにするために operator boolをオーバーロードします。 template <class T> class smart_ptr { T* p_; public: operator bool() const { return p_ != 0; } }; smart_ptr<int> p; /</int></class>…