enum type

Nov 9, 2009 at 1:06am
can you have an accessor function that returns an enum type?
Nov 9, 2009 at 1:11am
Yes, as long the enum is named.
Last edited on Nov 9, 2009 at 1:11am
Nov 9, 2009 at 1:22am
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 Nov 9, 2009 at 1:25am
Nov 9, 2009 at 1:29am
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.
Nov 9, 2009 at 1:43am
this is the header file for my shape object and line 11 is the line i define enum myColor?
Nov 9, 2009 at 1:52am
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 Nov 9, 2009 at 1:53am
Nov 9, 2009 at 1:58am
enum shapeColor {red, green, blue};


gives me the same error?
and i have not defined any macro with the same name?
Nov 9, 2009 at 2:06am
Are you using inclusion guards?

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