How to use daeElement -> clone()


I m trying to clone an element, update some of its values and push it to its library:

if (domJoint *joint = daeSafeCast<domJoint>(inst_joint->getUrl().getElement()))
if (daeElement *new_joint = joint->clone())
// calc new id …
// …

	new_joint-&gt;setAttribute("new_id", id.c_str());  // this crashes, new_joint is neither NULL nor an daeElement
	// ...
	// parent is the "library_joints" element


Can someone help me?


This assignment is necessary:

new_joint = joint->getParent()->add(new_joint);

Then, the access to attributes/elements of new_joint is possible.