Yes, your new code is fine. Please note, however, that in more complex cases, more subtle are possible:
#include <memory> struct foo { foo(std::shared_ptr<int> a, std::shared_ptr<int> b) { } }; struct bar { foo f; bar() : f(std::shared_ptr<int>(new int), std::shared_ptr<int>(new int)) { } }; int main() { bar b; }
will not be safe, since the order of evaluation of the arguments of the constructor foo is not specified in the list of initializers bar . The corresponding compiler can choose the depth or width of the first order of evaluation (or something else if they are all evaluated correctly in the end). This means that if the first new int succeeds, and the second, before the shared_ptr objects were constructed, the first selection to be executed can still occur.
If you find that you want to do this, there are two possible solutions, in addition to simply returning to the two-phase construction: the first can be a refactor, the second is to build shared_ptr first as panel elements, before f . Which one is most appropriate is a call to court, which, it seems to me, needs to be done in each case.
Flexo source share