Function Parameters without Names?

Salih Dincer salihdb at hotmail.com
Sun Feb 20 06:09:34 UTC 2022


On Saturday, 19 February 2022 at 23:37:01 UTC, Vijay Nayar wrote:
> 
> What is the main motivator to allow parameters with no names? 
> Do they get an automatic implied name like `_` or something?

The problem was about 
[here](https://dlang.org/spec/class.html#constructors), it should 
not be type inference: 
https://dlang.org/spec/function.html#function-attribute-inference

Do you think so? But it works when you open inactive codes and 
convert this(int) to this(T)! The program below throws an error 
about ```_param_0``` when compiling because the inferred type is 
not int.

```d
import std.conv;

class Foo
{
   int i;

   //   v=== type of inferred
   this(int)//(T i)
   {
     this.i = i;//.to!int;
   }

   string test()
   {
     return i.to!string;
   }
}

void main()
{
   long bar = 42;
   auto foo = new Foo(bar);
   assert(foo.test == "42"); /* Error:

   constructor `source.Foo.this(int _param_0)` is not callable 
using argument types `(long)`
   cannot pass argument `bar` of type `long` to parameter `int 
_param_0`

   */
}
```
The following doesn't work in a function outside the class:
```d
TYPE foo(TYPE) { return 42; }
```
The compiler gives the following error:
```undefined identifier TYPE```

SDB at 79


More information about the Digitalmars-d-learn mailing list