www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - function overloading of address

reply "sdvcn" <sdvcn 126.com> writes:
void ac(int aa)
{
}

void ac(void *a2)
{
}

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


who get "void ac(int aa)" address ?
Dec 02 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Dec 02 2014
next sibling parent reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
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
Dec 02 2014
parent "sdvcn" <sdvcn 126.com> writes:
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?
Dec 02 2014
prev sibling next sibling parent reply ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
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 wr=
ote:
 sdvcn:
=20
void ac(int aa)
{
}

void ac(void *a2)
{
}

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


who get "void ac(int aa)" address ?
=20 This code: =20 =20 void foo(int) {} void foo(void*) {} =20 void main() { auto pfoo =3D &foo; } =20 =20 Gives: =20 test.d(5,17): Error: cannot infer type from overloaded function symbol =
& foo
 [...]
=20
 How do you take the address of specific overload, though?
declare the necessary function type instead of auto: void function (int) pfoo =3D &foo;
Dec 02 2014
parent "sdvcn" <sdvcn 126.com> writes:
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.
Dec 02 2014
prev sibling next sibling parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
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
Dec 02 2014
prev sibling parent ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
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: =20 void function (int) pfoo =3D &foo;
=20 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.
Dec 02 2014