When trying to create a shared pointer to an object I come across this error
#include <iostream>
#include <vector>
class Foo {
public:
std::shared_ptr<Foo> getFoo(int i) {
auto foo = std::make_shared<Foo>(i);
//auto foo = std::shared_ptr<Foo>(new Foo(i)); "works"
return foo;
}
protected:
Foo(int i) {std::cout << "foo" << std::endl; }
};
int main(int argc, const char * argv[]) {
}
I get the buildtime error
Static_assert failed due to requirement 'is_constructible<Foo, int &>::value' "Can't construct object in make_shared"
I can avoid this by making the constructor private, But I would like to know why make_shared fails and and shared_ptr(new) works?