Not sure why converting from color_t* to float is a problem
I am having problems initializing members of a struct
Here is the struct I am trying to initialize:
Code:
typedef struct {
float Red;
float Green;
float Blue;
float Alpha;
} color_t;
I am trying to pass an array of floats to a function using pointers
Here is a snippet of the function (I augmented other parameters and the rest of the code in the function)
Code:
Light::Light(float * Colors) {
Color->Red = Colors[Red];
Color->Green = Colors[Green];
Color->Blue = Colors[Blue];
Color->Alpha = Colors[Alpha];
Material = Materials;
}
And of course it is giving me the following errors:
[errors]
C:\Documents and Settings\Charles Thibault\Desktop\ourengine\LightImplementation.cpp (15) : error C2059: syntax error : 'constant'
C:\Documents and Settings\Charles Thibault\Desktop\ourengine\LightImplementation.cpp (16) : error C2039: 'Color' : is not a member of 'color_t'
c:\documents and settings\charles thibault\desktop\ourengine\light.h(13) : see declaration of 'color_t'
[/errors]
Oh and by the way I '#defined' Red, Green, Blue, and Alpha as 0, 1, 2, and 3, respectively (Yes, I seriously need to do that otherwise I forget what element of the array to use).
EDIT: I don't know if it is legal to have the member variable and the #defines the same words, i.e Red, Gree, Blue and Alpha are the same names for both the members of the struct and the macros
However, I tried taking them out and I am still getting the same errors
Re: Not sure why converting from color_t* to float is a problem
Your code should work fine, except for:
Quote:
Originally posted by Shadow12345
Oh and by the way I '#defined' Red, Green, Blue, and Alpha as 0, 1, 2, and 3, respectively
Hehehe, there you have your problem.
You #define away the member variables' names! :D
Use constants instead, and you'll do fine.
This should be in the FAQ board as an argument of not using #define.
Clarification:
Code:
#define Red 1
struct C
{
int Red;
};
//Will be converted by the preprocessor to:
struct C
{
int 1;
};
//Which clearly is an error!