Is it safe and correct?
It works. That is, it has a well-defined behavior and does not leak (provided that it compiles).
But is it safe? It is a dangerous idea to have smooth pointers run freely. You must keep track of which pointers have been deleted and which have not; which indicate the memory to be deleted, and which are not.
It is much safer to use RAII-enabled handles to control your dynamically allocated objects, such as std::unique_ptr and std::shared_ptr (or force replacements). std::unique_ptr does not allow aliasing, and std::shared_ptr allows you to use aliases safely.
source share