I learnt that when have a user provided constructor in a class then the compiler will not implicitly generate a default constructor. Then I wrote the following code C d{};
in particular that I expected to fail(give error) because as per my understanding there is no default constructor for this class.
But to my surprise the program compiles with all compilers(gcc, clang, msvc, edg).
Demo
#include <initializer_list>
struct C
{
//we've a user provided function so no default ctor will be generated by compiler afaik
C(std::initializer_list<int> i)
{
}
void func(){}
};
int main()
{
C d{}; //GCC: ok, Clang:Ok, MSVC: Ok, EDG:Ok
d.func();
}
So my question is, why/how does the program C d{};
in particular work when there is no default constructor for C
.