lundi 23 novembre 2020

C++ : Default constructor for struct doesn't work? [duplicate]

Here is a code snipped which is not compilable under gcc 10.2.

struct Document {
   int id;

   Document() = default;
};

int main()
{
   const Document test;

   return 0;
}

Is it an expected behaviour? I believe that default constructor must initialize all internal members to default value and since int is a primitive type it must be 0 (at least in 99% of cases). Am I wrong?

Here is an output :

‘const struct Document’ has no user-provided default constructor

Aucun commentaire:

Enregistrer un commentaire