J
Jeff Massung
I am having a syntax issue that I hope someone else here knows how to
rectify...
I am loading an INI file and have a simple function to load values from
it. The function is overloaded with the different return types int,
double or string. A structure is defined:
typedef struct INI_KEY {
char strCategory[32];
char strKey[32];
union {
int iDefaultValue;
double dDefaultValue;
char strDefaultValue[32];
} def;
} INI_KEY;
In the implementation is a global array of INI_KEY's that list off
various categories, keys and their default value (the value to return if
it isn't in the INI):
const INI_KEY g_keys[] = {
{ "category", "keyInt", 0 },
{ "category", "keyDouble", 0.0 },
{ "category", "keyString", "foo" },
// ...
};
The problem I'm having is in the default value of the global array. The
compiler is trying to convert the double and string values to integers
and generating compiler errors. I'm sure there is a syntax to tell the
compiler what member of the union to use, I just don't know it. If it
makes a difference, I'm using MS VC++ 7.
rectify...
I am loading an INI file and have a simple function to load values from
it. The function is overloaded with the different return types int,
double or string. A structure is defined:
typedef struct INI_KEY {
char strCategory[32];
char strKey[32];
union {
int iDefaultValue;
double dDefaultValue;
char strDefaultValue[32];
} def;
} INI_KEY;
In the implementation is a global array of INI_KEY's that list off
various categories, keys and their default value (the value to return if
it isn't in the INI):
const INI_KEY g_keys[] = {
{ "category", "keyInt", 0 },
{ "category", "keyDouble", 0.0 },
{ "category", "keyString", "foo" },
// ...
};
The problem I'm having is in the default value of the global array. The
compiler is trying to convert the double and string values to integers
and generating compiler errors. I'm sure there is a syntax to tell the
compiler what member of the union to use, I just don't know it. If it
makes a difference, I'm using MS VC++ 7.