Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClass
- {
- private:
- std::auto_ptr<MyOtherClass> obj;
- public:
- MyClass()
- {
- obj = auto_ptr<MyOtherClass>(new MyOtherClass());
- }
- void reassignMyOtherClass()
- {
- // ... do funny stuff
- MyOtherClass new_other_class = new MyOtherClass();
- // Here, I want to:
- // 1) Delete the pointer object inside 'obj'
- // 2) Re-assign the pointer object of 'obj' to 'new_other_class'
- // so that 'obj' now manages 'new_other_class' instead of the
- // object that just got deleted manually
- }
- };
- void MyClass::reassignMyOtherClass()
- {
- // ... still, do more funny stuff (flashback humor :-)
- MyOtherClass new_other_class = new MyOtherClass();
- obj.reset(new_other_class);
- }
- obj.reset( new MyOtherClass() );
- MyClass():
- obj( new MyOtherClass() )
- {
- }
Add Comment
Please, Sign In to add comment