Nice try. Your code doesn't work, so you defer to something that does. Unfortunately, it still won't work...
Code: Select all
boost::shared_ptr<ISceneNode> a = smgr->addCubeSceneNode(10);
This won't work because the boost
shared_ptr doesn't know to call
grab() or
drop(). This would cause problems because the Irrlicht reference count is seperate from the
shared_ptr reference count. If the above line would even compile (it won't because the required constructor is explicit), it would result in the node being deleted without removing it from the scene graph. Boom!
Code: Select all
boost::shared_ptr<IReferenceCounted> a(new DerivedReferenceCounted);
a = a;
a = a;
a = a;
The self assignment problem is now fixed, and the initialization syntax is correct, but the previously mentioned problem is not fixed.
Regardless, no matter what you do, there are problems. The pointer needs to know if it is allowed to call
drop() or not. Actually, it needs to know if it should
grab() the pointer on construction or not.
Code: Select all
// this pointer should not be dropped unless it is grabbed
special_ptr<ISceneNode> a(smgr->addCubeSceneNode(10.f));
// this pointer should be dropped
special_ptr<ISceneNodeAnimator> b(smgr->createFlyCircleAnimator());
Sure, you could call
a->grab() in this case and that would work just fine. Unfortunately this doesn't work well when trying to write code that takes
special_ptr objects as parameters to functions.
The closest thing that would work correctly that is supplied by boost is the
boost::intrusive_ptr implementation.
Travis