d strings are the bane of my existance

Steven Schveighoffer schveiguy at gmail.com
Mon Dec 6 16:34:39 UTC 2021


On 12/5/21 11:24 AM, Chris Katko wrote:
> All I want:
> 
> ```d
> string ip_address = "192.168.1.1";
> auto x = new InternetAddress( ip_string, "8008");
> ```
> 
> ```d
> source/app.d(161,16): Error: none of the overloads of `this` are 
> callable using argument types `(string, int)`
> `std.socket.InternetAddress.this(scope const(char)[] addr, ushort port)`
> ```

I know you have solved your problem, but take a look at the error 
message here -- "not callable using argument types `(string, int)`", 
whereas your sample has types `(string, string)`. It always helps to 
post *exactly* the code that is causing the problem, not code that you 
thought you used. If you want to make it simpler for posting, test the 
simpler code.

I'm assuming to get that error you did something like:

```d
auto port = 8008;
auto x = new InternetAddress( ip_string, port);
```

This doesn't work, because port is inferred to be `int`, not `ushort`. 
You can fix by using `ushort` instead of `auto`, or using the literal 
right in the call.

-Steve


More information about the Digitalmars-d-learn mailing list