Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
The copy() Method

The copy() method defined for SoNode creates a copy of an instance of a node. If your node has no data other than fields and public children, then the copy() methods defined for SoNode and SoGroup should suffice.

However, if you have extra instance data in your node that needs to be copied, you will have to override the copy method. For example, if our Pyramid node class defined earlier contained a private integer member variable called count (for some private reason), the copy() method would look like this:

SoNode*
Pyramid::copy( SbBool copyConnections ) const
{
// Use the standard version of the copy method to create a
// copy of this instance, including its field data
Pyramid* newPyramid = ( Pyramid* )SoNode::copy( copyConnections );
// Copy the "count" field explicitly
newPyramid->count = count;
return newPyramid;
}