gpt4 book ai didi

c++ - 使用模板调用重载函数(unresolved overloaded function type compiler error)

转载 作者:太空狗 更新时间:2023-10-29 21:49:09 37 4
gpt4 key购买 nike

<分区>

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

我有一个函数为类继承层次结构中的一组类型重载,例如Share 与 FutureShare 和 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) { //... }

编译时出现以下错误:

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'

如何正确调用重载函数?我认为 TShare 会在调用 func 时解决过载问题?

编辑我忘了将重载函数标记为静态。

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com