Thread: Best way to do this...

  1. #1
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    Best way to do this...

    I have a long list of contstants which are #defined, and for each constant in the list there's two entries in another constant list (start and end)

    So...

    #define IDLE 0
    #define WALK 1

    // ...

    #define IDLE_START 0
    #define IDLE_END 22
    #define WALK_START 23
    #define WALK_END 50

    would be an example of the two lists. I want to clean this up a bit (this isn't my code) so I first opted for an enum:

    enum state { idle, walk, ... };
    But that still leaves the other list for which I don't know what to do.
    Basically, I need a way of connecting one constant to two other constants. I could whip something ugly up, but i'm looking for an elegant solution.

    Thanks in advance.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    After some tinkering, this is what I came up with...
    Code:
    const struct state
    {
        state(int s, int e) : start(s), end(e) {};
        int start;
        int end;
    } idle(0, 23), walk(24, 50);
    
    typedef const state& stateref;
    It seems to be a good solution.
    Thanks Eibro.

Popular pages Recent additions subscribe to a feed