I have following struct defined in a header file which I cannot edit (not allowed to):
struct Programma
{
enum {SERIE, FILM} programmaType;
char* titel;
char* zender;
time_t start;
time_t einde;
char* review;
union
{
Serie* serie;
Film* film;
} typeData;
};
I've tried:
Programma asd;
asd.programmaType = SERIE; //Error: identifier 'SERIE' is undefined
asd.programmaType = 0; //Error: a value of type 'int'cannot be assigned to an entity of type 'enum PRogramma::<unnamed>
and in a function with a pointer to a Programma struct as parameter replacing the '.' by '->', which gave me the same errors.
I think I'm doing the same thing as suggested here (How to use enum within a struct in ANSI C?), but I can't stop getting random errors.
EDIT: For some reason in Visual Studio when I type asd. the usual dropdown box comes up, but there's an option for 'Typedata' as well as 'SERIE' and 'FILM'. Personally I think there's something wrong with the declaration of the struct, but it was given, and I'm not supposed to edit it.
EDIT EDIT: I'm creating a C++ project in Visual Studio 2008, but every source file is either .h or .c. This is what we've been taught as 'C', but I'm starting to wonder how true that actually is.
It seems, by the errors messages, that you are actually not having a C program, but a C++ program. For that you have to use the scoping operator ::
as in
asd.programmaType = Programma::SERIE;
Assuming C, you're declaring a struct (without a typedef) incorrectly.
Try:
struct Programma asd;
replace
Programma asd;
by
struct Programma asd;
then asd.programmaType = SERIE;
should be accepted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With