Hi everyone,
I came across this problem when trying to compile some code that works in Visual Studio but not Xcode/gcc. Apparently, from what I read, this SHOULD be valid in C++ but gcc doesn't seem to like it. Here's a sample:
#include <stdio.h>
typedef enum _Type {
HEY, JUDE
} Type;
typedef struct _object {
int object_number;
int generation_number;
Type Type;
}object;
main()
{
printf("Hello, world!\n");
}
If I save the file as "main.cpp" and compiled for C++, I get:
main.cpp:10: error: declaration of 'Type _object::Type'
main.cpp:5: error: changes meaning of 'Type' from 'typedef enum _Type Type'
If I save the file as "main.c", it builds fine.
Doing some research I found that C has different namespaces for types and variables, but C++ didn't originally. The book I found this in said that it should have been incorporated into C++ but I think gcc doesn't have this fix. So, the question is, how can I fix it? I can't find anything in the Xcode or gcc docs to solve this problem, short of changing the names of the types (why someone did it like this to begin with I don't know). Thanks.