Is there any good practice or regulation on how to use a QSharedPointer
object as method parameter or return value of a method ?
By value:
LMNode::setParent(QSharedPointer<LMNode> parent)
{
this->parent = parent;
}
QSharedPointer<LMNode> LMNode::getParent()
{
return this->parent;
}
or better by reference:
LMNode::setParent(const QSharedPointer<LMNode>& parent)
{
this->parent = parent;
}
const QSharedPointer<LMNode>& LMNode::getParent()
{
return this->parent;
}
Sure, in the second version i avoid the increment of the reference counter and the changing of the QSharedPointer
object. But is there a stringent way how as I have to do?
QSharedPointer
object has the size of two normal pointers, so passing by reference would save 4 or 8 Bytes (depending on system architecture). Dont know, whever this can be an issue. Interesting article. – Incredulity