I have two functions that do nearly the same thing, the only difference is that one instantiates one of its variables while the other takes it as a parameter:
void f1()
{
myType o;
// do work on o
}
void f2(shared_ptr<myType> o)
{
// do work on o
}
This is because some callers need o after the work is done, while some others do not. There is a lot of work done, and right now keeping the functions in sync is a copy-paste affair (also changing "o." to "o->"). Is it possible to combine these into a single function, such that if the caller passes in an o, then that is used (as in f2), otherwise one is constructed (as in f1)? Perhaps by setting a default value in the signature?