samedi 23 juin 2018

aggregate syntax for initialisation in c++11/14

So I have the following code:

struct mystruct
{
    bool b1;
    bool b2;
}

class myclass
{
    myclass() :
        st ({true, true})
    {};
    mystruct st;
};

So, in visual studio 2017 this compiled ok. But in using gcc with the -c++11 flag it gave an error.

When I changed the flag to -c++14 then it built again no problem.

I have been reading about this, but I don't really get which is the "correct" syntax for each. My questions are:

  • is there a way to use aggregate initialisation that works for both c++11 and c++14?
  • What is the correct c++11 syntax?
  • What is the correct c++14 syntax?

Aucun commentaire:

Enregistrer un commentaire