Jump to page: 1 2 3
Thread overview
Address of overloaded functions
Jul 03, 2013
John Colvin
Jul 03, 2013
Artur Skawina
Jul 03, 2013
John Colvin
Jul 03, 2013
H. S. Teoh
Jul 03, 2013
Artur Skawina
Jul 03, 2013
H. S. Teoh
Jul 03, 2013
Artur Skawina
Jul 03, 2013
H. S. Teoh
Jul 03, 2013
Artur Skawina
Jul 03, 2013
Tyro[17]
Jul 04, 2013
Artur Skawina
Jul 03, 2013
H. S. Teoh
Jul 03, 2013
Artur Skawina
Jul 03, 2013
H. S. Teoh
Jul 03, 2013
Artur Skawina
Jul 03, 2013
Dicebot
Jul 03, 2013
John Colvin
Jul 03, 2013
Artur Skawina
Jul 04, 2013
Dicebot
Jul 04, 2013
John Colvin
Jul 03, 2013
Artur Skawina
July 03, 2013
Is there any way to take the address of any of an overloaded set of functions?

import std.stdio;

void foo(int a){ writeln("overload int"); }
void foo(long b){ writeln("overload long"); }

void main()
{
    auto b = &foo; //ambiguous => error
    b(2); //valid for either overload
}
July 03, 2013
On 07/03/13 16:52, John Colvin wrote:
> Is there any way to take the address of any of an overloaded set of functions?
> 
> import std.stdio;
> 
> void foo(int a){ writeln("overload int"); }
> void foo(long b){ writeln("overload long"); }
> 
> void main()
> {
>     auto b = &foo; //ambiguous => error
>     b(2); //valid for either overload
> }

    void function(long) b = &foo;

artur
July 03, 2013
On Wednesday, 3 July 2013 at 14:52:32 UTC, John Colvin wrote:
> Is there any way to take the address of any of an overloaded set of functions?
>
> import std.stdio;
>
> void foo(int a){ writeln("overload int"); }
> void foo(long b){ writeln("overload long"); }
>
> void main()
> {
>     auto b = &foo; //ambiguous => error
>     b(2); //valid for either overload
> }

http://dpaste.dzfl.pl/1e705a3b
July 03, 2013
On 07/03/13 17:03, Artur Skawina wrote:
> On 07/03/13 16:52, John Colvin wrote:
>> Is there any way to take the address of any of an overloaded set of functions?
>>
>> import std.stdio;
>>
>> void foo(int a){ writeln("overload int"); }
>> void foo(long b){ writeln("overload long"); }
>>
>> void main()
>> {
>>     auto b = &foo; //ambiguous => error
>>     b(2); //valid for either overload
>> }
> 
>     void function(long) b = &foo;

And if you meant for the overload resolution to happen at call-time, that's obviously not directly possible - there's no address of a /set/ of functions. You can use an alias, though:

    alias b = foo;

artur

July 03, 2013
On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote:
> On 07/03/13 16:52, John Colvin wrote:
>> Is there any way to take the address of any of an overloaded set of functions?
>> 
>> import std.stdio;
>> 
>> void foo(int a){ writeln("overload int"); }
>> void foo(long b){ writeln("overload long"); }
>> 
>> void main()
>> {
>>     auto b = &foo; //ambiguous => error
>>     b(2); //valid for either overload
>> }
>
>     void function(long) b = &foo;
>
> artur

Thanks, that works
July 03, 2013
On Wednesday, 3 July 2013 at 15:05:00 UTC, Dicebot wrote:
> On Wednesday, 3 July 2013 at 14:52:32 UTC, John Colvin wrote:
>> Is there any way to take the address of any of an overloaded set of functions?
>>
>> import std.stdio;
>>
>> void foo(int a){ writeln("overload int"); }
>> void foo(long b){ writeln("overload long"); }
>>
>> void main()
>> {
>>    auto b = &foo; //ambiguous => error
>>    b(2); //valid for either overload
>> }
>
> http://dpaste.dzfl.pl/1e705a3b

It's a pity that only work within an aggregate (the documentation actually says only classes)
July 03, 2013
On 07/03/13 17:17, John Colvin wrote:
> On Wednesday, 3 July 2013 at 15:05:00 UTC, Dicebot wrote:
>> On Wednesday, 3 July 2013 at 14:52:32 UTC, John Colvin wrote:
>>> Is there any way to take the address of any of an overloaded set of functions?
>>>
>>> import std.stdio;
>>>
>>> void foo(int a){ writeln("overload int"); }
>>> void foo(long b){ writeln("overload long"); }
>>>
>>> void main()
>>> {
>>>    auto b = &foo; //ambiguous => error
>>>    b(2); //valid for either overload
>>> }
>>
>> http://dpaste.dzfl.pl/1e705a3b
> 
> It's a pity that only work within an aggregate (the documentation actually says only classes)

http://forum.dlang.org/thread/xamuenbcabnhrtqjjizw@forum.dlang.org#post-mailman.1122.1332633715.4860.digitalmars-d-learn:40puremagic.com

artur
July 03, 2013
On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote:
> On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote:
> >On 07/03/13 16:52, John Colvin wrote:
> >>Is there any way to take the address of any of an overloaded set of functions?
> >>
> >>import std.stdio;
> >>
> >>void foo(int a){ writeln("overload int"); }
> >>void foo(long b){ writeln("overload long"); }
> >>
> >>void main()
> >>{
> >>    auto b = &foo; //ambiguous => error
> >>    b(2); //valid for either overload
> >>}
> >
> >    void function(long) b = &foo;
> >
> >artur
> 
> Thanks, that works

This is interesting. How does C++ handle this? (Or does it?)


T

-- 
Debian GNU/Linux: Cray on your desktop.
July 03, 2013
On 07/03/13 17:27, H. S. Teoh wrote:
> On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote:
>> On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote:
>>> On 07/03/13 16:52, John Colvin wrote:
>>>> Is there any way to take the address of any of an overloaded set of functions?
>>>>
>>>> import std.stdio;
>>>>
>>>> void foo(int a){ writeln("overload int"); }
>>>> void foo(long b){ writeln("overload long"); }
>>>>
>>>> void main()
>>>> {
>>>>    auto b = &foo; //ambiguous => error
>>>>    b(2); //valid for either overload
>>>> }
>>>
>>>    void function(long) b = &foo;
>>>
>>> artur
>>
>> Thanks, that works
> 
> This is interesting. How does C++ handle this? (Or does it?)

The same - the context determines which overload is chosen, and ambiguity is an error.

artur
July 03, 2013
On Wed, Jul 03, 2013 at 05:41:25PM +0200, Artur Skawina wrote:
> On 07/03/13 17:27, H. S. Teoh wrote:
> > On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote:
> >> On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote:
> >>> On 07/03/13 16:52, John Colvin wrote:
> >>>> Is there any way to take the address of any of an overloaded set of functions?
> >>>>
> >>>> import std.stdio;
> >>>>
> >>>> void foo(int a){ writeln("overload int"); }
> >>>> void foo(long b){ writeln("overload long"); }
> >>>>
> >>>> void main()
> >>>> {
> >>>>    auto b = &foo; //ambiguous => error
> >>>>    b(2); //valid for either overload
> >>>> }
> >>>
> >>>    void function(long) b = &foo;
> >>>
> >>> artur
> >>
> >> Thanks, that works
> > 
> > This is interesting. How does C++ handle this? (Or does it?)
> 
> The same - the context determines which overload is chosen, and ambiguity is an error.

Oh, so it tells the difference by whether you write

	void (*p)(int) = foo;

or

	void (*p)(long) = foo;

?

I guess that makes sense.


T

-- 
There are 10 kinds of people in the world: those who can count in binary, and those who can't.
« First   ‹ Prev
1 2 3