Re: [Dev-C++] Make switch condition an enum
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2002-10-18 14:42:19
|
> I have the following chunk of code, and I've been asked to make the switch
> (SomeError) statement use an enum. Well I was told to "make that an enum".
>
> How would I create the enum and use it in the switch statement?
>
>
> // Get error strings
> switch (SomeError)
> {
> case ERROR_ONE:
> DebugOut = _T("Error One!");
> break;
>
> case ERROR_TWO:
> DebugOut = _T("Error Two!");
> break;
>
> default:
> DebugOut = _T("Unspecified error!");
> break;
> }
Something like this:
enum ErrorType { ERROR_ONE = 1, ERROR_TWO }
and then the same code with SomeError being of type ErrorType rather than
int (as I assume it is here).
For those of you who are interested, a helmet saved my life yesterday, after
a crash at 90 kph.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|