I am reviewing an approach I see commonly used in storing objects (e.g. a socket client object). Namely, usage of a static container to hold the objects. Said objects are created by some helper function as follows:create_client(params) {  ...  client* cl = new client(...);  return cl;}The thing that confused me at first was function called like this:if (!create_client (...))   //generate error messagei.e. a copy of the pointer just seems to be thrown away.But on investigation I see this in the client constructor:client::client(...) {    ...    coll[id] = this;}Where coll is a map of id to a pointer to the object. But anyway, just a collection.  coll is static (not sure if that is relevant).Is there a name for this idiom?  Is it good practice?
Is storing pointer (of new'd object) in static collection from object constructor a common idiom in C++
c++
Not so familiar with C++, but I do not like the assignment into the static structure from the constructor, because:1) Introduces a dependency: now the contained class needs to know about the containing instance. You cannot reuse the class without either rewritting or using the same structure.2) It causes a reference leak from the constructor, since the reference to the class is available to other threads before the constructor has finished executing.At the very least, I would have moved the instance assignment from the constructor to the create_client function.