 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Siegfried Heintze Guest
|
Posted: Fri Feb 24, 2006 5:06 pm Post subject: How to pass overloaded function as function pointer argument |
|
|
I have several overloaded functions with the same name. I want to call
std::lower_bound with one of these functions. std::lower_bound accepts a
function pointer just fine without any overloading. However, when I add an
additional overloaded function, the compiler (g++ 3.2) understandibly gets
confused. How do I disambiguate?
Thanks,
Siegfried
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
John Potter Guest
|
Posted: Sat Feb 25, 2006 12:06 pm Post subject: Re: How to pass overloaded function as function pointer argu |
|
|
On 24 Feb 2006 11:01:37 -0500, "Siegfried Heintze"
<siegfried (AT) heintze (DOT) com> wrote:
| Quote: | I have several overloaded functions with the same name. I want to call
std::lower_bound with one of these functions. std::lower_bound accepts a
function pointer just fine without any overloading. However, when I add an
additional overloaded function, the compiler (g++ 3.2) understandibly gets
confused. How do I disambiguate?
|
With a cast.
bool f (int, int);
bool f (double, double);
lower_bound(v.begin(), v.end(), 42,
static_cast<bool (*) (int, int)>(f));
You could also use a pointer variable.
bool (*fInt) (int, int) (f);
lower_bound(v.begin(), v.end(), 42, fint);
John
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Mar 03, 2006 1:06 pm Post subject: Re: How to pass overloaded function as function pointer argu |
|
|
hello John
Just Go Through the "DDJ April 2006" article having heading
"Overloading Overloading"
You will get answer to your question.
regards
vishal sharma
John Potter wrote:
| Quote: | On 24 Feb 2006 11:01:37 -0500, "Siegfried Heintze"
siegfried (AT) heintze (DOT) com> wrote:
I have several overloaded functions with the same name. I want to call
std::lower_bound with one of these functions. std::lower_bound accepts a
function pointer just fine without any overloading. However, when I add an
additional overloaded function, the compiler (g++ 3.2) understandibly gets
confused. How do I disambiguate?
With a cast.
bool f (int, int);
bool f (double, double);
lower_bound(v.begin(), v.end(), 42,
static_cast<bool (*) (int, int)>(f));
You could also use a pointer variable.
bool (*fInt) (int, int) (f);
lower_bound(v.begin(), v.end(), 42, fint);
John
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|