RE: [Dev-C++] Make switch condition an enum
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-10-18 23:37:34
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Daniel Glenfield
> Sent: Friday, October 18, 2002 2:45 PM
> To: dev...@li...
> Subject: [Dev-C++] Make switch condition an enum
>
>
>
> Hi,
> 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?
Enumerators are user defined integral types taking discrete, user
defined values. For example:
// Mon=0, Tue=1, Wed=2, Thu=8, Fri=9 Sat=20 Sun=21
enum Days { Mon, Tue, Wed, Thu=8, Fri, Sat=20, Sun};
The above is the type. It does not occupy space the same as int, or a
class does not occupy space by itself. Its objects do:
Days oneday=Wed;
switch(oneday)
{
case Mon:
// ...
}
> // 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;
> }
What is that _T you are using all the time anyway? It seems to me
something like "boxing" (as it happens in .NET for example).
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|