Thread overview
function overloading of address
Dec 03, 2014
sdvcn
Dec 03, 2014
bearophile
Dec 03, 2014
H. S. Teoh
Dec 03, 2014
sdvcn
Dec 03, 2014
ketmar
Dec 03, 2014
sdvcn
Dec 03, 2014
H. S. Teoh
Dec 03, 2014
ketmar
December 03, 2014
void ac(int aa)
{
}

void ac(void *a2)
{
}

int main(string[] argv)
{
auto v = &ac;  //<--- who address
}


who get "void ac(int aa)" address ?
December 03, 2014
sdvcn:

> void ac(int aa)
> {
> }
>
> void ac(void *a2)
> {
> }
>
> int main(string[] argv)
> {
> auto v = &ac;  //<--- who address
> }
>
>
> who get "void ac(int aa)" address ?

This code:


void foo(int) {}
void foo(void*) {}

void main() {
    auto pfoo = &foo;
}


Gives:

test.d(5,17): Error: cannot infer type from overloaded function symbol & foo

Bye,
bearophile
December 03, 2014
On Wed, Dec 03, 2014 at 02:11:54AM +0000, bearophile via Digitalmars-d wrote:
> sdvcn:
> 
> >void ac(int aa)
> >{
> >}
> >
> >void ac(void *a2)
> >{
> >}
> >
> >int main(string[] argv)
> >{
> >auto v = &ac;  //<--- who address
> >}
> >
> >
> >who get "void ac(int aa)" address ?
> 
> This code:
> 
> 
> void foo(int) {}
> void foo(void*) {}
> 
> void main() {
>     auto pfoo = &foo;
> }
> 
> 
> Gives:
> 
> test.d(5,17): Error: cannot infer type from overloaded function symbol & foo
[...]

How do you take the address of specific overload, though?


T

-- 
Arise, you prisoners of Windows
Arise, you slaves of Redmond, Wash,
The day and hour soon are coming
When all the IT folks say "Gosh!"
It isn't from a clever lawsuit
That Windowsland will finally fall,
But thousands writing open source code
Like mice who nibble through a wall.
-- The Linux-nationale by Greg Baker
December 03, 2014
On Wednesday, 3 December 2014 at 02:20:32 UTC, H. S. Teoh via Digitalmars-d wrote:
> On Wed, Dec 03, 2014 at 02:11:54AM +0000, bearophile via Digitalmars-d wrote:
>> sdvcn:
>> 
>> >void ac(int aa)
>> >{
>> >}
>> >
>> >void ac(void *a2)
>> >{
>> >}
>> >
>> >int main(string[] argv)
>> >{
>> >auto v = &ac;  //<--- who address
>> >}
>> >
>> >
>> >who get "void ac(int aa)" address ?
>> 
>> This code:
>> 
>> 
>> void foo(int) {}
>> void foo(void*) {}
>> 
>> void main() {
>>     auto pfoo = &foo;
>> }
>> 
>> 
>> Gives:
>> 
>> test.d(5,17): Error: cannot infer type from overloaded function symbol & foo
> [...]
>
> How do you take the address of specific overload, though?
>
>
> T

how take (void foo(int)) address?
December 03, 2014
On Tue, 2 Dec 2014 18:18:26 -0800
"H. S. Teoh via Digitalmars-d" <digitalmars-d@puremagic.com> wrote:

> On Wed, Dec 03, 2014 at 02:11:54AM +0000, bearophile via Digitalmars-d wrote:
> > sdvcn:
> > 
> > >void ac(int aa)
> > >{
> > >}
> > >
> > >void ac(void *a2)
> > >{
> > >}
> > >
> > >int main(string[] argv)
> > >{
> > >auto v = &ac;  //<--- who address
> > >}
> > >
> > >
> > >who get "void ac(int aa)" address ?
> > 
> > This code:
> > 
> > 
> > void foo(int) {}
> > void foo(void*) {}
> > 
> > void main() {
> >     auto pfoo = &foo;
> > }
> > 
> > 
> > Gives:
> > 
> > test.d(5,17): Error: cannot infer type from overloaded function symbol & foo
> [...]
> 
> How do you take the address of specific overload, though?
declare the necessary function type instead of auto:

  void function (int) pfoo = &foo;


December 03, 2014
On Wednesday, 3 December 2014 at 02:31:20 UTC, ketmar via Digitalmars-d wrote:
> On Tue, 2 Dec 2014 18:18:26 -0800
> "H. S. Teoh via Digitalmars-d" <digitalmars-d@puremagic.com> wrote:
>
>> On Wed, Dec 03, 2014 at 02:11:54AM +0000, bearophile via Digitalmars-d wrote:
>> > sdvcn:
>> > 
>> > >void ac(int aa)
>> > >{
>> > >}
>> > >
>> > >void ac(void *a2)
>> > >{
>> > >}
>> > >
>> > >int main(string[] argv)
>> > >{
>> > >auto v = &ac;  //<--- who address
>> > >}
>> > >
>> > >
>> > >who get "void ac(int aa)" address ?
>> > 
>> > This code:
>> > 
>> > 
>> > void foo(int) {}
>> > void foo(void*) {}
>> > 
>> > void main() {
>> >     auto pfoo = &foo;
>> > }
>> > 
>> > 
>> > Gives:
>> > 
>> > test.d(5,17): Error: cannot infer type from overloaded function symbol & foo
>> [...]
>> 
>> How do you take the address of specific overload, though?
> declare the necessary function type instead of auto:
>
>   void function (int) pfoo = &foo;

Thank you.
December 03, 2014
On Wed, Dec 03, 2014 at 04:31:11AM +0200, ketmar via Digitalmars-d wrote:
> On Tue, 2 Dec 2014 18:18:26 -0800
> "H. S. Teoh via Digitalmars-d" <digitalmars-d@puremagic.com> wrote:
[...]
> > How do you take the address of specific overload, though?
>
> declare the necessary function type instead of auto:
> 
>   void function (int) pfoo = &foo;

Ah, of course. I'm getting too used to type inference. :-P


T

-- 
If you look at a thing nine hundred and ninety-nine times, you are perfectly safe; if you look at it the thousandth time, you are in frightful danger of seeing it for the first time. -- G. K. Chesterton
December 03, 2014
On Tue, 2 Dec 2014 18:40:45 -0800
"H. S. Teoh via Digitalmars-d" <digitalmars-d@puremagic.com> wrote:

> On Wed, Dec 03, 2014 at 04:31:11AM +0200, ketmar via Digitalmars-d wrote:
> > On Tue, 2 Dec 2014 18:18:26 -0800
> > "H. S. Teoh via Digitalmars-d" <digitalmars-d@puremagic.com> wrote:
> [...]
> > > How do you take the address of specific overload, though?
> >
> > declare the necessary function type instead of auto:
> > 
> >   void function (int) pfoo = &foo;
> 
> Ah, of course. I'm getting too used to type inference. :-P
me too. the first thing i tried was `&foo(0)` to hint the type.