You cannot do this unless you pass a pointer to the pointer or a reference to the pointer (example here):
void replaceBy(Foo*& foo, Foo* bar) {
delete foo;
foo = bar;
}
//...
foo->replaceBy(foo, bar);
Which would defeat the purpose of replaceBy
being a non-static member function.
There is also the überevil macro way to do this (don't):
#define FOO_REPLACE_BY(foo, bar) do {delete foo; foo = bar;} while(0)
I recommend that you overload operator=
and stay away from pointers when possible, or at least use smart pointers (which allow for pointer assignment without memory leaks).