[osg-users] Copy constructor and assignment operator

Yip Leng Wong yiplengwong at rocketmail.com
Tue Sep 9 01:32:05 PDT 2008


Hi,
 
As I'm a new user of OpenSceneGraph, pardon me for this simple question:
 
For the following class:
 
class Foo
{
public:
    Foo() {}
   virtual ~Foo() {}
 
private:
    osg::ref_ptr<osg::Node> mNode;
};
 
since mNode is a pointer, is it a must to provide a copy constructor and assignment operator for deep copy to prevent dangling pointer?
 
If there is a need to provide the copy constructor and assignment operator, is it correct as illustrated by the codes below?
 
Foo(const Foo& other)
{
    mNode = other.mNode;
}
 
Foo& operator=(const Foo& other)
{
    if (this == &other)
        return *this;
 
   mNode = new osg::Node;
    mNode = other.mNode;
    return *this;
}
 
Thanks,
Yip Leng


      New Email names for you! 
Get the Email name you've always wanted on the new @ymail and @rocketmail.. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/sg/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080909/2da3abae/attachment-0002.htm>


More information about the osg-users mailing list