codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#define BOOST_DISABLE_THREADS #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> class Foo { public: void SetX(const int value) { this->elements[0] = value; } void SetY(const int value) { this->elements[1] = value; } void SetZ(const int value) { this->elements[2] = value; } void SetW(const int value) { this->elements[3] = value; } void Print() { printf( "%d, %d, %d, %d\n", this->elements[0], this->elements[1], this->elements[2], this->elements[3]); } private: int elements[4]; }; class Hoge { public: virtual void Func1() // != Func4 { const boost::shared_ptr<Foo> p(pFoo); p->SetX(1); p->SetY(3); p->SetZ(5); p->SetW(7); p->Print(); } virtual void Func2() // == Func4 { const boost::shared_ptr<Foo> sp(pFoo); Foo * const p(sp.get()); p->SetX(1); p->SetY(3); p->SetZ(5); p->SetW(7); p->Print(); } virtual void Func3() // == Func4 { const boost::shared_ptr<Foo> p(pFoo); Func3Core(p); } virtual void Func4() { const boost::shared_ptr<Foo> sp(pFoo); Func4Core(sp.get()); } static void Func3Core(const boost::shared_ptr<Foo> & sp) { Foo * const p(sp.get()); p->SetX(1); p->SetY(3); p->SetZ(5); p->SetW(7); p->Print(); } static void Func4Core(Foo * const p) { p->SetX(1); p->SetY(3); p->SetZ(5); p->SetW(7); p->Print(); } void SetFoo(const boost::shared_ptr<Foo> & pNewFoo) { this->pFoo = pNewFoo; } boost::shared_ptr<Foo> GetFoo() const { return this->pFoo; } private: boost::shared_ptr<Foo> pFoo; };
Private
[
?
]
Run code
Submit