Calling an overloaded function using templates (error of an unrealized overloaded compiler type)

Possible duplicate:
How to get the address of an overloaded member function?

I have a function overloaded for a set of types in an inheritance inheritance hierarchy, for example. Share with FutureShare and OptionShare.

virtual unsigned rank() const { return getValue(*this, rank_, &ShareUtils::getRank); } template<typename TShare , typename TMember, typename TGetMemberFunc > TValue& getValue(const TShare& share, boost::optional<TMember>& member, TGetMemberFunc func) { if(!member) { member.reset(func(share)); } return *member; } boost::optional<unsigned> rank_; //------- static unsigned ShareUtils::getRank(const Share& share) { //... } static unsigned ShareUtils::getRank(const OptionShare& option) { //... } static unsigned ShareUtils::getRank(const FutureShare& future) { //... } 

When compiling, I get the following error:

 Share.h: In member function `virtual unsigned int Share::rank() const': Share.h:25: error: no matching function for call to `Share::getValue(const Share&, boost::optional<unsigned int>&, <unresolved overloaded function type>) const' 

How to properly call an overloaded function? I realized that TShare will allow overload when calling func?

EDIT I forgot to mention the overloaded static functions.

+2
c ++ templates function-overloading
source share
1 answer

This will not compile, because ShareUtils::getRank does not apply to one function, but to a family of functions (there are several signatures for this name).

You want to use a function pointer function to suppress ambiguity, which means you need to know from the rank function that getRank should call (which should not be a problem in your case):

 virtual unsigned rank() const { return getValue(*this, rank_, (unsigned (ShareUtils::*)(const Share&)) &ShareUtils::getRank); } 
+2
source share

All Articles