A
Akshay Loke
Hi all,
I have this function from a class MFnDagNode,
addChild( MObject & child, unsigned int index = kNextPos, bool
keepExistingParents = false );
which takes an object reference as first input parameter (ignore the
rest since those are default)
now in another class, I have:
MFnDagNode parent;
parent.addChild(node.object());
Where node is MfnDependencyNode&
And node.object() returns MObject
This gives me error
‘error: no matching function for call to
‘MfnDagNode::addChild(Mobject)’
Note: candidates are: Mstatus MFnDagNode::addChild(MObject&, unsigned
int, bool)
Now I am not sure why this doesn’t work and the object doesn’t get
implicitly cast to the MObject& reference argument, but I am assuming
that could be because the node.object() returns a temporary const
object and it cannot be cast to a MObject& reference…
So this is the way I have done this…
const MObject& nodeObjectConstRef = node.object();
MObject& nodeObjectRef = const_cast<MObject&> (nodeObjectConstRef);
parent.addChild(nodeObjectRef);
and This works!
Initially I tried this,
MObject& nodeObjectConstRef = node.object();
parent.addChild(nodeObjectConstRef );
but that didn’t work … it gives the error,
‘error: invalid initialization of non-const reference of type
‘MObject&’ from a temporary of type ‘MObject’’
The first method above is working, but am not sure if I am suppressing
something using the const_cast…
Thanks
Akshay
I have this function from a class MFnDagNode,
addChild( MObject & child, unsigned int index = kNextPos, bool
keepExistingParents = false );
which takes an object reference as first input parameter (ignore the
rest since those are default)
now in another class, I have:
MFnDagNode parent;
parent.addChild(node.object());
Where node is MfnDependencyNode&
And node.object() returns MObject
This gives me error
‘error: no matching function for call to
‘MfnDagNode::addChild(Mobject)’
Note: candidates are: Mstatus MFnDagNode::addChild(MObject&, unsigned
int, bool)
Now I am not sure why this doesn’t work and the object doesn’t get
implicitly cast to the MObject& reference argument, but I am assuming
that could be because the node.object() returns a temporary const
object and it cannot be cast to a MObject& reference…
So this is the way I have done this…
const MObject& nodeObjectConstRef = node.object();
MObject& nodeObjectRef = const_cast<MObject&> (nodeObjectConstRef);
parent.addChild(nodeObjectRef);
and This works!
Initially I tried this,
MObject& nodeObjectConstRef = node.object();
parent.addChild(nodeObjectConstRef );
but that didn’t work … it gives the error,
‘error: invalid initialization of non-const reference of type
‘MObject&’ from a temporary of type ‘MObject’’
The first method above is working, but am not sure if I am suppressing
something using the const_cast…
Thanks
Akshay