By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,335 Members | 1,814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,335 IT Pros & Developers. It's quick & easy.

enum across objects

P: n/a
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

Nov 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
marfi95 wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 13 '06 #2

P: n/a

Victor Bazarov wrote:
marfi95 wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Maybe I still need to learn some stuff, but you obviously need to
re-learn some basic stuff too, like manners !

Nov 13 '06 #3

P: n/a

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!

--
Bob R
POVrookie
Nov 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.