OK, so consider the following situations:
1) I have an object X who owns its own resources (via pointers). It creates these resources itself and also gives access to these resources through a public interface. Therefore, the pointers in the class should be shared_ptr and return weak_ptr, right?
I know shared_ptr means shared ownership, but it's also the only pointer from which you can return a non-owning, observing pointer. Would there actually be a need for another type of pointer such as scoped_ptr that explicitly owns ownership, but allows non-intrusive, non-owning pointers to it to be returned?
2) I have an object X which should own its own resources. However, it does not create these resources, instead relying on others to pass in the resources, and the assuming ownership of these resources. Is this right? Should the creator of the resources assume ownership and lend non-owning pointers to the object X?
So far as I can tell, there is no way for object X to acquire ownership properly.
A weak_ptr cannot be initialized with a new resource, so object X cannot accept a weak_ptr to the resource unless the one who passes the resource owns, or shares, the ownership (in other words, uses a shared_ptr). And a weak_ptr cannot be assigned to a shared_ptr or scoped_ptr either. So how does one usually do this? Is the design flawed?
3) I have a resource in another class which I shall hand to class X for storing. The resource is a non-pointer, so a reference is passed to class X. Then class X needs to store a pointer to this resource it is passed. I don't like the idea of using a raw pointer because it could be confused to a pointer which needs to be deleted. So, I made a simple do_not_delete container and wrapped it inside. Is this a good solution? Is there any smart pointers for this purpose?
Appreciate any and all answers.