View Single Post
  #6 (permalink)  
Old 08-13-2007, 05:38 AM
Opiate
Posts: n/a
Quote:
Originally Posted by Bench View Post
Code:
#include <string>

enum { Continue, Won, Lost, Invalid };


int lookup( std::string str )
{
    const int elems = 3;
    std::string arr[elems] = { "Continue", "Won", "Lost" };
    for( int i(0); i!=elems; ++i )
        if( arr[i]  == str )
            return i;

    return Invalid;
}

int main()
{
    int i = lookup("Won");

    switch( i )
    {
    case Continue:
        //do something for Continue
        break;
    case Won:
        //Do something for Won
        break;
    case Lost:
        //Do something for Lost
        break;
    }
}
You didn't name the enum, you passed an Int to that function, and returned a variable that doesn't exist. Did you mean to do that? I am missing anything?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote