Did you know; we need this operator!

Salih Dincer salihdb at hotmail.com
Mon Sep 16 13:11:28 UTC 2024


On Monday, 16 September 2024 at 08:47:51 UTC, Kagamin wrote:
> As for scope extension, C# has extended scope statements:
>
> This is normal scoped statement:
> ```C#
> with(Days){ ... }
> ```
>
> This is extended scoped statement:
> ```C#
> {
> 	with Days;
> 	...
> }
> ```

Moving on to C++, there is no direct operator to shorten enum 
member names. However, there are several methods to make enum 
members more readable. You can shorten long enum names using 
typedef or using:

```CPP
#include <iostream>
using namespace std;

//* <--For other solution remove the first character
enum Days
{
   Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
};

typedef Days Day;

/*/
//  Namespace Usage:
//  You can place enum members inside
//  a namespace to use shorter names:


namespace Days
{
   enum Day
   {
     Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
   };
}

using namespace Days;//*/

int main()
{
     Day today = Sunday;

     cout << "Hello " << today;

     return 0;
}
```

 From these examples, we see that C++ is proactive in solving the 
problem.

SDB at 79


More information about the Digitalmars-d mailing list