dimanche 16 juin 2019

Structure initialization error: could not convert from ‘

I have the following code:

struct Vec { double x=0, y=0, z=0; };

Vec orig = {1,2,3};

GCC 4.8.4 shows the following error:

error: could not convert ‘{1, 2, 3}’ from ‘<brace-enclosed initializer list>’ to ‘Vec’
 Vec orig = {1,2,3};
                  ^

When I change take away the equals sign

Vec orig {1,2,3};

there comes another error:

error: no matching function for call to ‘Vec::Vec(<brace-enclosed initializer list>)’
 Vec orig {1,2,3};
                ^

How can I initialize the structure properly without creating a constructor?

Aucun commentaire:

Enregistrer un commentaire