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?
EDIT:
This methods is being called like this:
std::shared_ptr<T> first;
std::shared_ptr<T> last = first;
const std::shared_ptr<T> link = std::make_shared<T>(some_arguments_here);
So the references are references to objects and they may increase the use count, still.