jeudi 3 mars 2016

In place member initialization and aggregate initialization

I have this simple struct and a function taking it:

struct S
{
    int a;
};

void foo(S){}

This works fine.

But if I change int a; to int a{0}; VisualStudio (2013 and 2015) complains:

error C2664: 'void foo(S)': cannot convert argument 1 from 'initializer list' to 'S'

I can't find corresponding rule for this in the documentation. But both gcc and clang accept this without problem.

Aucun commentaire:

Enregistrer un commentaire