ice icon indicating copy to clipboard operation
ice copied to clipboard

Consider using factory methods for classes that enable_shared_from_this and have init methods

Open pepone opened this issue 1 year ago • 0 comments

In a few place we have separate init methods because you cannot call std::shared_from_this from a constructor.

void foo = make_shared<Foo>();
foo->init();

An alternative is to have a factory method createFoo that calls init, to avoid forgetting this additional initialization step.

We use the make_shared and init pattern in Slice library, PHP, Ruby and Python extensions. Probably in more places.

pepone avatar Jan 29 '24 15:01 pepone