I have implemented Chain of Responsibility design pattern and each element in a chain is a shared_ptr. In this case I want to have first as a start of the chain and last and an end of the chain to be able to add new chain itms using last. In the function below link is the current chain element created as a local variable and what I add to the chain using the function below:
void addLink(std::shared_ptr<ILink>& first, std::shared_ptr<ILink>& last, std::shared_ptr<ILink>& link)
{
if (first == nullptr)
{
first = link;
last = first;
}
else
{
last->setSuccessor(link);
last = link;
}
}
Is it a good practice to use all references and will it increase the ref count?
Aucun commentaire:
Enregistrer un commentaire