If you can move to C++11, you should use std::shared_ptr
and your problem is solved. shared_ptr
will take care about number of users of the pointer and will automatically clean it up when last user disposes it. And I strongly recommend transferring to modern C++, it solves great amount of problems.
You can also take a look at Boost SmartPtr - it does essentailly the same and can be used before C++11.
You could also try to implement such utility on your own, but you have to make sure to implement it properly - with reference counter incrementing and decrementing correctly in the spirit of Rule of Three
If you have to use raw pointers, then there's no way in standard C++ to guarantee that a pointer will (or will not) be deallocated by a function.
The only way to inform other programmers that your function wants to take ownership of the pointer (and will delete it) is via documentation, either in-code (with comments), or with a separate document (if you create an API for example).
However, you should strongly consider whether the function should take ownership of the pointer. Is it reasonable for function to own it? If not, just leave it and let allocating function take care of deallocation.