Thread overview | |||||
---|---|---|---|---|---|
|
November 14, 2018 Problem with opBinary | ||||
---|---|---|---|---|
| ||||
Hi, Just a little weird thing I noticed and don't know why it is: I have a FilePath struct and I wanted to make it work with the "~" operator and an additional string. So I've created a global funct: FilePath opBinary(string op:"~")(FilePath p1, string p2){ return FilePath(p1, p2); } The problem is that this funct is only callable with the following code: auto vlcPath = programFilesPath.opBinary!"~"(`VideoLAN\VLC`); And it is not callable using the ~ operator directly. It says unable to call with types FilePath and string When I rewrite the opBinary funct as a member of the FilePath struct, everything is working fine. The problem is only happening when opBinary is a global funct. (I'm using LDC Win64) Is it a bug or is there an explanation to this? |
November 14, 2018 Re: Problem with opBinary | ||||
---|---|---|---|---|
| ||||
Posted in reply to realhet | On Wednesday, November 14, 2018 2:54:27 AM MST realhet via Digitalmars-d- learn wrote:
> Hi,
>
> Just a little weird thing I noticed and don't know why it is:
>
> I have a FilePath struct and I wanted to make it work with the "~" operator and an additional string.
>
> So I've created a global funct:
>
> FilePath opBinary(string op:"~")(FilePath p1, string p2){
> return FilePath(p1, p2);
> }
>
> The problem is that this funct is only callable with the following code:
>
> auto vlcPath = programFilesPath.opBinary!"~"(`VideoLAN\VLC`);
>
> And it is not callable using the ~ operator directly. It says unable to call with types FilePath and string
>
> When I rewrite the opBinary funct as a member of the FilePath struct, everything is working fine. The problem is only happening when opBinary is a global funct. (I'm using LDC Win64)
>
> Is it a bug or is there an explanation to this?
In D, all overloaded operators must be member functions.
- Jonathan M Davis
|
November 14, 2018 Re: Problem with opBinary | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | Thanks, this make it clear. (This also explains the existence of opBinaryRight) |
Copyright © 1999-2021 by the D Language Foundation