如果功能超载,则BOOST PHOENIX成员功能操作员无法编译
Boost phoenix member function operator fails to compile if function has overload
我想将Boost Phoenix成员功能运算符用于具有过载的类功能,例如此处。
以下示例失败:
#include <boost/phoenix/phoenix.hpp>
#include <boost/phoenix/operator.hpp>
using namespace std;
using namespace boost::phoenix::placeholders;
struct A
{
int m_id = 1;
int func() const { return 1; }
void func(int id) { m_id = id; }
};
int main()
{
A *a = new A;
auto retVal = (arg1->*&A::func)()(a);
return 0;
}
错误:
In function 'int main()': 17:21: error: no match for 'operator->*'
(operand types are 'const type {aka const
boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::
tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l>
>}' and '<unresolved overloaded function type>') 17:21: note: candidate is: In
file included from /usr/include/boost/phoenix/operator/arithmetic.hpp:13:0,
from /usr/include/boost/phoenix/operator.hpp:13, from /usr/include/boost
/phoenix/phoenix.hpp:13, from 1: /usr/include/boost/proto/operators.hpp:295:9:
note: template<class Left, class Right> const typename
boost::proto::detail::enable_binary<boost::proto::domainns_::deduce_domain,
boost::proto::detail::not_a_grammar,
boost::mpl::or_<boost::proto::is_extension<Arg>,
boost::proto::is_extension<Right> >, boost::proto::tagns_::tag::mem_ptr, const
Left&, const Right&>::type boost::proto::exprns_::operator->*(Left&&,
Right&&) BOOST_PROTO_DEFINE_OPERATORS(is_extension, deduce_domain) ^
/usr/include/boost/proto/operators.hpp:295:9: note: template argument
deduction/substitution failed: 17:28: note: couldn't deduce template parameter
'Right'
但是,如果我对void func(int id) { m_id = id; }
发表评论,则可以按预期工作。
我该如何判断要使用的超载?
处理(成员)功能指针到过载集合总是很痛苦。您需要将地址投放到具有所需过载的确切签名的指针。在您的情况下,用于选择int A::func()
:
auto retVal = (arg1->*static_cast<int (A::*)() const>(&A::func))()(a);
或更多可读性,但基本相同:
const auto memFctPtr = static_cast<int (A::*)() const>(&A::func);
auto retVal = (arg1->*memFctPtr)()(a);
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 需要帮助操作员过载,这样我才能显示功能
- 操作员<<如何使用机械手功能
- 操作员比功能快
- 带有成员(操作员[])功能的Indoke_Result
- 当直接分配时,为什么此功能指针分配起作用,而不是与有条件的操作员一起使用
- 在C 中的功能模板中使用过载的操作员
- 如何使用Sfinae为容器创建模板功能,并根据操作员推断返回类型
- 任何操作员,功能调用和构造函数的通用持续时间表
- 如果功能超载,则BOOST PHOENIX成员功能操作员无法编译
- 为什么COUT在朋友函数中不起作用,该功能超载了操作员&lt;&lt;这是一个iStream运算符
- 操作员过载功能
- 在C 中使用功能作为操作员过载
- C++过载+操作员友情功能
- 如何使用此独特的操作员重载功能
- 过载操作员功能失败
- 与操作员'<<'不匹配 有人可以帮助解决无效功能错误吗?[C++]
- 没有操作员发现升压read_xml功能错误
- 操作员重新分配功能/结构返回什么
- 使用操作员<<的记录功能