C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to pass overloaded function as function pointer argument

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Siegfried Heintze
Guest





PostPosted: Fri Feb 24, 2006 5:06 pm    Post subject: How to pass overloaded function as function pointer argument Reply with 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?

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





PostPosted: Sat Feb 25, 2006 12:06 pm    Post subject: Re: How to pass overloaded function as function pointer argu Reply with quote



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






PostPosted: Fri Mar 03, 2006 1:06 pm    Post subject: Re: How to pass overloaded function as function pointer argu Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.