I have two C++ structures, Rect
which is a floating point rectangle and iRect
which is the same, but with integers:
struct iRect {
int X;
int Y;
int W;
int H;
};
struct Rect {
float X;
float Y;
float W;
float H;
};
Currently I can construct these using the syntax Rect{1.2, 2.4, 4.2, 0.2};
.
Now I want to make these implicitly convertible, so I create a new constructor for Rect:
Rect(iRect iR) {
X = (float)iR.X;
Y = (float)iR.Y;
W = (float)iR.W;
H = (float)iR.H;
}
And I get: error C2512: 'Rect' : no appropriate default constructor available
No big deal, I'll just define an empty default constructor.
But now I get error C2440: 'initializing' : cannot convert from 'initializer-list' to 'Rect'
So I have to define another constructor for four floats, three floats, two floats and one float to have the same behaviour as before. Also this example is simplified: Rect is actually a union with two Vec2
types as well so I would also have to define a constructor for Rect (Vec2 a, Vec2 b)
.
Normally all these constructors are generated by the compiler. Is there any way for me to define my Rect(iRect iR)
constructor without stopping the compiler from generating all those other constructors?