In the following code,
typedef unsigned long col24;
inline col24 MakeRGB24(int R, int G, int B) { return ...; }
struct blitdata
{
union
{
int Flags, Stretch;
col24 Luminance;
};
// (other members)
};
int main()
{
blitdata BlitData =
{
MakeRGB24(0, 0, 0),
// ...
};
}
why does the first initializer in the initializer list of BlitData
give the following error:
Non-constant-expression cannot be narrowed from type
col24
(akaunsigned long
) toint
in initializer list
Why is the compiler trying to initialize the int
member of the union
with the initializer whose type is col24
instead of using it to initialize the col24
member?
The compiler suggests that I static_cast
the result of MakeRGB24
to int
, but this could result in an unwanted narrowing.
How can the Luminance
member be correctly initialized using the result of MakeRGB24
in the initializer list?
Edit: blitdata
should stay POD.