Hi Rabbi,

The destructor of most OSG class is deliberately made protected so
your can't delete it directly using delete, it also prevents the class
from being created on the stack.

Why?  This is a C++ programming trick that can help prevent misue of
C++ classes that are reference counted, and the OSG uses reference
almost everywhere for it's memory management of scene graph classes so
it's crucial that users use reference counting rather than try and mix
and match objects memory management.

The final answer to your question, how do you delete... well you don't
you leave it up to smart pointers and reference counting to do the
job.  You simple do:

  {
      osg::ref_ptr<Node> node = new Node; // create node on stack and
take a reference to it.
  } // ref_ptr goes out of scope and decrements the reference count,
and if it goes to 0, then it's deleted.

Robert.

On Mon, Jun 1, 2009 at 3:54 PM, Rabbi Robinson <longa...@gmail.com> wrote:
> Hi,
>
> When I tried
>
> Node* node = new Node;
> delete node;
>
> there is a compiler error saying destructor protected. How can I delete node 
> that I am sure I no longer use.
>
> Thank you!
>
> Cheers,
> Rabbi
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=13275#13275
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to