I have this code in a new C++ editor I'm trying out (CLion):
struct screenPoint {
float x = 0, y = 0;
screenPoint(float x_, float y_): x{x_}, y{y_}{}
};
struct position {
screenPoint ul;
float width = 0, height = 0;
position(screenPoint p, float w, float h): ul{p},width{w},height{h}{}
};
Near the end is the initialisation statement ul{p}, which I thought was a valid C++ way to use brace initialisation. However, CLion complains:
Incompatible types in initialiser: Types 'float' and 'screenPoint' are not compatible.
Note: there are no compiler errors or warnings, and the code works as expected.
If I change it to ul(p) the error goes away.
Now, I know that screenPoint does not have a constructor that accepts another screenPoint but is that necessary in initialisation like this?
Aucun commentaire:
Enregistrer un commentaire