Elaborated type refers to a typedef error on Clang
c++, clang
Solution
In C++ you do not need to use `typedef` with `enum`s: when you write `enum XYZ`, compilers creates a type `XYZ`, so you can later write `XYZ varOfTypeXYZ`, as opposed to `enum XYZ varOfTypeXYZ`.
Rewriting `media` as follows will fix the problem:
class media {
public:
enum mediatype
{
audio,
video,
text,
data
};
};
Demo on ideone.
The problem with writing `enum media::mediatype` is that your declaration does not create an `enum` tag `mediatype`, it creates a type called `mediatype`. The `enum` that you define is anonymous, so the reference `enum media::mediatype` cannot be resolved properly.
Therefore, another way to fix this problem is to add a tag to `enum` definition, like this:
class media {
public:
typedef enum mediatype
{
audio,
video,
text,
data
} mediatype;
};
Demo on ideone.
Problem
I am getting the following error using this compiler Apple LLVM version 5.1 (clang-503.0.40) Code is here test.h ``` class media { public: typedef enum { audio, video, text, data }mediatype; }; ``` test.cpp ``` #include "test.h" int main() { enum media::mediatype medias[] = {media::audio, media::video}; for (int i=0; (i < sizeof(medias) / sizeof(enum media::mediatype)); ++i) { } } ``` test.cpp:5:15: error: elaborated type refers to a typedef enum media::mediatype medias[] = {media::audio, media::video}; test.cpp:6:58: error: reference to 'mediatype' is ambiguous for (int i=0; (i < sizeof(medias) / sizeof(enum media::mediatype)); ++i) If I remove the enum keyword as follows the code compiles ``` #include "test.h" int main() { media::mediatype medias[] = {media::audio, media::video}; for (int i=0; (i < sizeof(medias) / sizeof(media::mediatype)); ++i) { } } ``` Can someone say why clang is complaining Thanks