Module function conflicting with reserve function

Peter Campbell peteypoo at pm.me
Tue Nov 6 20:40:11 UTC 2018


Hi there. I've been playing with D and have encountered this 
really awkward behaviour. Basically I'm getting a compiler error 
inside a function I wrote in my module as it thinks I'm trying to 
call itself with invalid parameters, when actually I want it to 
call the reserve function on the array itself. Is this a bug or 
expected behaviour? It seems quite strange and potentially 
annoying to me.

https://run.dlang.io/is/9YyAI9

module bob;

struct Bob
{
     private ubyte[] _data;
}

void reserve(ref Bob system, in size_t capacity)
{
     // bob.reserve(ref Bob system, const(ulong) capacity) is not 
callable with (ubyte[], const(ulong)).
     system._data.reserve(capacity);
}

void main()
{
}


More information about the Digitalmars-d-learn mailing list