Why can't we make reference variables?
Tommi
tommitissari at hotmail.com
Thu Aug 30 06:30:15 PDT 2012
On Thursday, 30 August 2012 at 11:53:14 UTC, bearophile wrote:
> Tommi:
>
>> // This prints 1, so we called the actual method
>
> I think in D methods have precedence over free functions.
>
> Bye,
> bearophile
Yes, but to me the ambiguity of that example is in whether or not
implicit deferencing of pointers has precedence over uniform
function call syntax. Apparently it does, but it's not that
obvious that it would.
struct MyStruct
{
int _value = 0;
void increment()
{
++_value;
}
}
void increment(ref MyStruct* ptr)
{
++ptr;
}
void main()
{
MyStruct* ptrMyStruct = new MyStruct();
// Are we incrementing the pointer using UFCS or
// are we calling the member function in MyStruct?
ptrMyStruct.increment();
}
More information about the Digitalmars-d
mailing list