programming with "enum"

This is a discussion on programming with "enum" within the C++ Programming forums, part of the General Programming Boards category; I want to return the enumerator indentifier itself, not the enumerator value. But we're supposed to be able to do ...

  1. #16
    Registered User
    Join Date
    Jun 2005
    Posts
    75
    I want to return the enumerator indentifier itself, not the enumerator value. But we're supposed to be able to do that using only the one function I have written there. Am I using the wrong kind of function or what?

  2. #17
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    The only way to return that - presuming you mean the string 'scalene' etc - is to use a function that returns a string.

    I'm not entirely sure you're on the same planet as me otherwise.

    I can kind of see what you mean, kinda.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #18
    *this
    Join Date
    Mar 2005
    Posts
    498
    Then apply what I showed you to your function.

    Like I posted.............

    Code:
    switch(type) 
       {
          case scalene: return "scalene";
          case isosceles: return "isosceles";
          case equilateral: return "equilateral";
          case noTriangle: return "No Triangle";
          default: return "Error";
       }
    And declare your function to return a string.

  4. #19
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    alright i think you are missing the point..

    when you enumarate stuff it basicly puts numbers on them as i said before

    Code:
    enum Test {zero, one, two, three};
    //its just like this:
    int zero = 0;
    int one = 1;
    //etc..
    // what the enum statement does is make them like macros or int's if you will
    // Zero = 0.. so lets say:
    
    return zero;
    // this is exactly the same thing as:
    return 0;
    // now to return the name and pirnt it out you can do what i suggested you or what JoshR suggested..

  5. #20
    Registered User
    Join Date
    Jun 2005
    Posts
    75
    Thanks. I got it now. Sorry for seeming so dense about this stuff... I'm just learnin'.

  6. #21
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Quote Originally Posted by MyntiFresh
    Thanks. I got it now. Sorry for seeming so dense about this stuff... I'm just learnin'.
    no problem, we were all like that when we were learning.. and rememeber if you dont understand something reread it... i know that you wont actualy reread something because i never did either

  7. #22
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    just FYI: don't worry too much about getting this whole enum thing down... you probably won't ever use it again... I once read an essay by Bjarne Stroustrup in which he said he wished enum was never part of the language because it's not very useful and doesn't fit in with the rest of the language... you can find the essay somewhere in General Discussions...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #23
    Registered User
    Join Date
    Jun 2005
    Posts
    75
    Quote Originally Posted by major_small
    just FYI: don't worry too much about getting this whole enum thing down... you probably won't ever use it again... I once read an essay by Bjarne Stroustrup in which he said he wished enum was never part of the language because it's not very useful and doesn't fit in with the rest of the language... you can find the essay somewhere in General Discussions...
    Thanks! I'm very glad to hear that. LOL

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21