View Full Version : Help! this no work! Why?

01-29-2001, 02:08 PM
I have this,
typedef struct {
union {
GLfloat v[3];
struct { GLfloat r,g,b;};
}; } vRGB;

but when it have this,
vRGB Returnrgb(...)
{ GLfloat vn[3]
//...here I calculate what vn values are.
return (vRGB) vn[0];
I get this:
zats.cpp(36) : error C2440: 'type cast' : cannot convert from 'float' to 'vRGB'
No constructor could take the source type, or constructor overload resolution was ambiguous

WHY? Please help!
vRGB is = to float! I use union to access either as float or struct. So why no work? This is VC++ v6 compiler. Is it bug in compiler?
How to fix?

01-29-2001, 05:28 PM
The compiler is right. Your datatype is not easy to read but it is certainly not something that can be converted to a float.

Serge K
01-29-2001, 06:31 PM
vRGB Returnrgb(...)
{ vRGB vn;
return vn;

01-30-2001, 03:12 AM
To sum up and explain what have been said.

vRGB is NOT equal to float as you said, it's equal to float[3]. You try to typecast a float into a float[3] which does not work.