Liste d'initialisation avec tableau
Bonjour je n'arrive pas du tout à faire arriver compiler le code suivant, j'ai l'erreur suivante avec g++-4.5.1:
Code:
1 2 3
| g++-4.5 -o main.o -c main.cpp -std=c++0x
main.cpp: In constructor A::A(B, B, B):
main.cpp:17:63: error: bad array initializer |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| struct B
{
B() = default;
B(const B &b) = default;
B(int a, int b) : x(a), y(b) {}
int x,y;
};
struct A
{
//A(B a, B b, B c) : i( { {a.x,a.y}, {b.x,b.y}, {c.x,c.y} } ) {}
//A(B a, B b, B c) : i( {a,b,c} ) {}
A(B a, B b, B c) {}
B i[3];
};
int main()
{
B x(1,2);
B y(3, 4);
B z(5, 6);
A a(x, y, z);
return 0;
} |
Aucun des deux code en commentaires ne fonctionne alors qu'avec un tableau de type int par exemple et en adaptant le code sa compile avec la nouvelle sémantique c++0x.
Merci d'avance!