Jump to content
  • Advertisement
Sign in to follow this  

Ambiguous pointer to overloaded method

This topic is 4311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following class declaration:
class A
  void B(bool);
  bool B();
And elsewhere I try to take a pointer to A::B
This results in a compiler error. Is there any way to tell the compiler which version I want? Currently, I'm using a local class to wrap the bool A::B() call in a functor but I was hoping there was a better way (besides renaming my methods :)).

Share this post

Link to post
Share on other sites
The compiler selects the function according to the type of the pointer you are assigning the expression to. For example:

void (A::*foo)(bool) = &A::B; selects void A::B(bool)
bool (A::*foo)() = &A::B; selects bool A::B()

Since mem_fun is a function template, you can normally use parameter type deduction but here, the expression &A::B can have two different types, two different values. It is thus unsurprising that the parameter type deduction mechanism would fail. You need to tell the compiler which one to use, either, as Skizz points out by forcing one version or another of mem_fun or by casting the expression results to the appropriate pointer type: e.g. std::mem_fun(static_cast<bool (A::*)()>(&A::B)).

Skizz's approach is the easiest solution in this case -- but it might not be in another (e.g. when more type manipulations happen in the template).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!