enum type

can you have an accessor function that returns an enum type?
Yes, as long the enum is named.
Last edited on
enum myColor {red, green, blue};

class shape
{
public:
shape();
myColor get_color();
private:
myColor color;

};

like this?

there is an error as thus:
1>shape.h(11) : error C2011: 'myColor' : 'enum' type redefinition
1>shape.h(11) : see declaration of 'myColor'

explain if you will
Last edited on
Apparently, you already defined 'myColor' somewhere else as something else. If that's not the case, I'll need to see which one is line 11.
this is the header file for my shape object and line 11 is the line i define enum myColor?
Then I'm pretty sure there's a name clash.
http://msdn.microsoft.com/en-us/library/sksadsda.aspx

See what happens if you rename the enum to something else.

EDIT: It's also possible that the file is being included twice. Are you using inclusion guards?
Last edited on
enum shapeColor {red, green, blue};


gives me the same error?
and i have not defined any macro with the same name?
Are you using inclusion guards?

do you mean #ifdefined
or is there a certain lib i am missing?
1
2
3
4
#ifndef HEADERNAME_H
#define HEADERNAME_H
//header contents
#endif 
Topic archived. No new replies allowed.