enum across objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marfi95

    #1

    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::MyMeth od()
    {
    myEnum passVal; // local instance

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

    Object1::MyMeth od2(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

  • Victor Bazarov

    #2
    Re: enum across objects

    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::MyMeth od()
    {
    myEnum passVal; // local instance
    >
    MyMethod2(passV al::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(passVa l);

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

    MyMethod(Item1) ;
    }
    >
    Object1::MyMeth od2(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


    Comment

    • marfi95

      #3
      Re: enum across objects


      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::MyMeth od()
      {
      myEnum passVal; // local instance

      MyMethod2(passV al::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(passVa l);
      >
      (which is really not necessary, what's the extra local object for?)
      or do
      >
      MyMethod(Item1) ;
      >
      }

      Object1::MyMeth od2(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 !

      Comment

      • BobR

        #4
        Re: enum across objects


        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


        Comment

        Working...