473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

enum across objects

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
3 1408
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't...
7
by: Aryeh M. Friedman | last post by:
If have something like the following declartion: enum foo {One,Two,....,Ten}; How do I determine how many elements (enumerations)... in this case it is obviously 10 but I don't want to hard...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
by: Anonieko Ramos | last post by:
Answer: http://weblogs.asp.net/tims/archive/2004/04/02/106310.aspx by Tim Sneath I've come across the situation on a number of occasions when coding where I've wanted to convert from a string...
8
by: Joe | last post by:
I have a .cs file which is linked to several other projects. All my classes in this file are defined as internal. I would like to have an enum defined as well in the namespace but I get an error...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
13
by: At_sea_with_C | last post by:
Consider the following code: #include <stdio.h> #define SOMEVAL 1234 enum tree_types { PINE = 10, BIRCH, LARCH, OAK = 100, MAPLE, ELM, WILLOW }; void print_val(enum tree_types tree) {...
3
by: Peri | last post by:
I have 3 layers. First - UI Layer (Windows Application - Thick Client) Second - Biz Layer (DLL) Third - Messaging Layer (DLL) The Messaging Layer is referenced in Biz Layer and Biz Layer is...
3
by: Gangreen | last post by:
I have the following enum. ** * An enum to represent types of mechanics. * * @author * @version 1.0 */ public enum Mechanics { ISOLATION(0),
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.