samedi 19 juin 2021

Struct initialization with {} and ()

When I have a struct

   struct Point
    {
    int x;
    int y;
    int z;
    }

Why it's possible to write

Point p = {10, 20, 30};
Point p0 {10, 20, 30};
auto p1 = Point{10, 20, 30};

Using {}. But I can't write with ()

Point p(10,10,10);
auto p1 = Point(10,10,10);

With error

Error   C2440   'initializing': cannot convert from 'initializer list' to 'Point '  

Aucun commentaire:

Enregistrer un commentaire