I noticed that I cannot instantiate an object as a make_shared parameter (see example bellow). Since
I am not really experienced with templates, the definition of the make_shared
template< class T, class... Args > shared_ptr<T> make_shared( Args&&... args );
does not reveal to me why make_shared({0}) fails.
Can someone explain why this happens?
class Alpha
{
int mValue;
bool mBool;
public:
Alpha(int value, bool lbool) :mValue(value), mBool(lbool){}
};
class Beta
{
Alpha mAlpha;
public:
explicit Beta(Alpha alpha): mAlpha(alpha){}
};
int main()
{
Alpha a{0, true};
Beta b1(1, a); // ok
Beta b2(1, {0, true}); //ok
auto pB1 = std::make_shared<Beta, Alpha>({ 0, true }); // ok
auto pB2 = std::make_shared<Beta>({ 0, true }); // make_shared does not take 1 arguments
auto pB3 = std::make_shared<Beta>(1, a); // ok
auto pB4 = std::make_shared<Beta>(1, {0, true}); // Err: make_shared does not take 2 arguments
auto pB5 = std::make_shared<Beta>(1, Alpha{0, true}); // ok
auto pB6 = std::make_shared<Beta>(1, Alpha{ 0, true }); // ok
auto pB7 = std::make_shared<Beta, Alpha>(1, {0, true }); // Err: make_shared does not take 2 arguments
}
*edit1: added an extra property in Alpha
*edit2: added new cases, still am not sure why pB7 fails but pB1 can some one explain that?