mardi 5 février 2019

c++11 initializer_list doesn't work for literal constant value of embedded object?

I've got a simple program in c++11:

#include<initializer_list>
#include<map>
#include<vector>
using namespace std;
struct A{
    int i;
    struct B{
        int i;
        int j;
    };
}a={2,{3,4}};

g++-7 compiles and gives error:

error: too many initializers for 'A'
 }a={2,{3,4}};
            ^

I just wonder how can I declare an object of A using literal constants, how to fix it?

Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire