nested function overloading

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 22 12:42:48 UTC 2022


On 6/22/22 2:05 AM, monkyyy wrote:
> On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer wrote:
>> And you can also use an inner struct to define overloaded functions.
> 
> I believe templates make a better bandaid
> ```d
> void main(){
>      template bar(){
>          void bar_(int){}
>          void bar_(float){}
>          alias bar=bar_;
>      }
>      bar(1);
>      bar(3.14);
> }
> ```

Wow, I never thought of that, it's a great idea! You don't even need to 
use the alias.

```d
void main(){
     template bar(){
         void bar(int){}
         void bar(float){}
     }
     bar(1);
     bar(3.14);
}
```

-Steve


More information about the Digitalmars-d-learn mailing list