#include <iostream>
#include <memory>
class Base
{
public:
Base() {}
};
class Derived : public Base
{
public:
Derived() {}
Derived(std::initializer_list<std::pair<int, std::shared_ptr<Base>>>) {}
};
int main(int argc, char ** argv)
{
auto example = new Derived({
{ 0, std::make_shared<Derived>() }
});
return 0;
}
It works (live preview) normally, but when I try to use std::make_shared
with the std::initializer_list
as argument I got errors:
auto example = new Derived({
{ 0, std::make_shared<Derived>({
{ 0, std::make_shared<Derived>() }
}) }
});
As you can see here on the live preview.
error: too many arguments to function...
It works only when I do this (live preview):
auto example = new Derived({
{ 0, std::make_shared<Derived>(std::initializer_list<std::pair<int, std::shared_ptr<Base>>> {
{ 0, std::make_shared<Derived>() }
}) }
});
What I want to know is: Why it works only when I pass the std::initializer_list
as argument on std::make_shared
instead of using {{}}
just like this:
auto example = new Derived({ { 0, std::make_shared<Base>() } });
Is that possible to make std::make_shared
accept it?
Thanks in advance.