enum across objects

M

marfi95

All,

I have defined a bunch a enums in a standard header file (outside of an
object) that I want to share across objects. I thought the right
approach would be to create the definitions globally, but then create
the instances in each of the objects that needs to use them. However
this is causing me a problem. I thought I could use the scope
identifier, but guess not. What I was trying was this:(compiler told
me it was undefined).

In .h header outside of any objects

enum myEnum
{
Item1,
Item2
} ;

Then in my object where I want to use it:

Object1::MyMethod()
{
myEnum passVal; // local instance

MyMethod2(passVal::Item1); // this causes the problem.....
}

Object1::MyMethod2(myEnum eVal)
{
Object2 obj;
obj(eVal); //object 2 would also need to
know, so I had put the definitions in
// common header ?
}


Is there another way to do this (or should I just go back and use
constants) ?

Thanks,
Mark
 
V

Victor Bazarov

marfi95 said:
I have defined a bunch a enums in a standard header file (outside of
an object) that I want to share across objects. I thought the right
approach would be to create the definitions globally, but then create
the instances in each of the objects that needs to use them. However
this is causing me a problem. I thought I could use the scope
identifier, but guess not. What I was trying was this:(compiler told
me it was undefined).

In .h header outside of any objects

enum myEnum
{
Item1,
Item2
} ;

Then in my object where I want to use it:

Object1::MyMethod()
{
myEnum passVal; // local instance

MyMethod2(passVal::Item1); // this causes the problem.....

Where did you learn this syntax? What if you need to pass an 'int',
would you do

int blah;

MyMethod42(blah::777);

? I guess not. What would you do instead? You would either define
the object of type 'int' and *initialise* it with 777, and then pass
the object into the other function, *OR* simply pass the damn value
into the function. Same with enums. You ought to either do

myEnum passVal = Item1;

MyMethod(passVal);

(which is really not necessary, what's the extra local object for?)
or do

MyMethod(Item1);
}

Object1::MyMethod2(myEnum eVal)
{
Object2 obj;
obj(eVal); //object 2 would also need to
know, so I had put the definitions in
// common header ?
}


Is there another way to do this (or should I just go back and use
constants) ?

You should just go back and re-learn some basic stuff, I guess.

V
 
M

marfi95

Victor said:
Where did you learn this syntax? What if you need to pass an 'int',
would you do

int blah;

MyMethod42(blah::777);

? I guess not. What would you do instead? You would either define
the object of type 'int' and *initialise* it with 777, and then pass
the object into the other function, *OR* simply pass the damn value
into the function. Same with enums. You ought to either do

myEnum passVal = Item1;

MyMethod(passVal);

(which is really not necessary, what's the extra local object for?)
or do

MyMethod(Item1);


You should just go back and re-learn some basic stuff, I guess.

V

Maybe I still need to learn some stuff, but you obviously need to
re-learn some basic stuff too, like manners !
 
B

BobR

marfi95 wrote in message ...
Maybe I still need to learn some stuff, but you obviously need to
re-learn some basic stuff too, like manners !

You post outside the guidelines of the FAQ, and then have the nuts to "bite
the hand that feeds you"!?!

I think you owe Mr. Bazarov an apology!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top