I have a function that has two instances of classes as arguments:
void cookPasta(const Tomato& tomato, const Meat* meat)
{
if (meat != nullptr)
cookPastaWithMeat(tomato, *meat);
else
cookPastaWithoutMeat(tomato);
}
As the function shows, an instance of Tomato
is always required, whereas Meat
is optional and a nullptr
can be passed instead. I do this to allow the cookPasta
function to be called even if the user has never declared an instance of the Meat
class.
Is it bad practice to mix references and pointers in the function signature?