[Issue 1006] no ambiguity error given if getting function address

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 24 13:31:28 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1006


wbaxter at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wbaxter at gmail.com




------- Comment #2 from wbaxter at gmail.com  2007-02-24 15:31 -------
It's also very common to use overloads for properties.

void prop(int p) { return mProp=p; }
int prop() { return mProp; }

This is a problem for callback/sigslot mechanisms that very often want to call
property-like functions.

   caller ~= (int x){ obj.prop=x; }
vs
   caller ~= &obj.prop;

The former introduces an extra layer of indirection, is slightly wordy, and is
potentially problematic if 'obj' happens to go out of scope.  The latter is
currently ambiguous.

Apparently a cast can be used currently:
   caller ~= cast(void function(int))&obj.prop;
but it is just too ugly.  And it's also semantically incorrect and unsafe.  I'm
not casting I'm trying to disambiguate.  And it's unsafe because the cast will
succeed even if obj.prop is a float* or anything else.

This is apparently an old proposal (according to Chris N-S) to disambiguate
without requiring a cast:
   caller ~= &obj.prop(int);

That would be great if that could be done without making the grammar ambiguous.

For generic programming purposes, this should also work:
   alias Tuple!(int) ArgTup;
   caller ~= &obj.prop(ArgTup);


-- 



More information about the Digitalmars-d-bugs mailing list