How to call a constructor with an empty initiailizer_list in c++17?

70 Views Asked by At

Consider this code:

class Foo
{
public:
    Foo(){cout<<"empty"<<endl;}
    Foo(initializer_list<int>){cout<<"init_list"<<endl;}
};

int main()
{
    Foo(); // empty
    Foo{}; // empty
    Foo({}); // init_list for c++14, empty for c++17
}

I am wondering why they behave differently between C++14 and C++17, and how to construct a Foo with an empty initializer_list in C++17?

0

There are 0 best solutions below