Sunday, 18 August 2013

std::shared_ptr initialization: make_shared(new Foo) vs shared_ptr(new Foo)

std::shared_ptr initialization: make_shared(new Foo) vs shared_ptr(new Foo)

What's the difference between:
std::shared_ptr<int> p = std::shared<int>(new int);
and
std::shared_ptr<int> p = std::make_shared(new int);
?
Which one should I prefer and why?
P. S. Pretty sure this must have been answered already, but I can't find a
similar question.

No comments:

Post a Comment