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 message
i.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?
if (!create_client(...))
? – Dan Pichelman Jun 18 '14 at 16:32client_create
and later use it ascreate_client
. – SJuan76 Jun 18 '14 at 17:00