C++:将模板回调方法传递给另一个方法:无法将‘<unresolved overloaded function type> 转换为指针
C++: passing the template callback method into the other method: cannot convert ‘<unresolved overloaded function type> to pointer
我有一个容器,用于存储包含模板回调的结构。
同时回调签名不包含模板参数。
插入时,出现错误:
cannot convert ‘<unresolved overloaded function type>’ to ‘smb1_subdecoder::send_subflow_premature_end_msg_t’ {aka ‘void (smb1_subdecoder::*)(long unsigned int, unsigned char, long unsigned int, unsigned char)’}
note: initializing argument 4 of
‘void smb1_subdecoder::store_subflow_bunch_on_open(
smb1_subdecoder::handle_t, uint64_t, CIFS_RESOURCE_TYPE,
smb1_subdecoder::send_subflow_premature_end_msg_t,
smb1_subdecoder::send_subflow_premature_end_msg_t)’
send_subflow_premature_end_msg_t send_subflow_premature_end_rq_msg,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
插入代码(此处错误):
store_subflow_bunch_on_open(
handle(response_msg.file_id), response_msg.msg_id,
static_cast<CIFS_RESOURCE_TYPE>(parm_open2_rsp->resource_type),
&send_subflow_premature_end_msg<ntdec_cifs_close_request>,
&send_subflow_premature_end_msg<ntdec_cifs_close_response>);
定义:
存储方式:
void smb1_subdecoder::store_subflow_bunch_on_open(
handle_t handle, uint64_t subflow_msg_id, CIFS_RESOURCE_TYPE resource_type,
send_subflow_premature_end_msg_t send_subflow_premature_end_rq_msg,
send_subflow_premature_end_msg_t send_subflow_premature_end_rsp_msg) { ... }
send_subflow_premature_end_msg_t:
typedef void (smb1_subdecoder::*send_subflow_premature_end_msg_t)
(uint64_t, uint8_t, uint64_t, uint8_t);
用于发送提前结束消息的模板函数(签名不依赖于上述模板参数):
template<class NTDEC_END_OBJECT_T>
void smb1_subdecoder::send_subflow_premature_end_msg(uint64_t subflow_msg_id, uint8_t close_reason,
uint64_t header_msg_id, uint8_t side)
{
NTDEC_END_OBJECT_T end_msg;
_d_smb->proto_fill(end_msg, subflow_msg_id);
end_msg.header_msg_id = header_msg_id;
if (_d_smb->transport() == decoder_smb::TRANSPORT::NETBIOS)
{
const auto* netbios_msg = _d_smb->get_proto_parent<ntdec_object>();
if (netbios_msg)
set_parent_msg_id(end_msg, netbios_msg->msg_id);
}
end_msg.side = (side == -1) ? _d_smb->get_last_data_side() : side;
_d_smb->stream().send_message(end_msg);
}
当 constructing a pointer to member.
时,您必须明确地使用 class 名称限定非静态成员的名称
(强调我的)
- If the operand is a qualified name of a non-static member, e.g.
&C::member
, the result is a prvalue pointer to member function or
pointer to data member of type T in class C. Note that neither &member
nor C::member
nor even &(C::member)
may be used to initialize a
pointer to member.
例如
store_subflow_bunch_on_open(
handle(response_msg.file_id), response_msg.msg_id,
static_cast<CIFS_RESOURCE_TYPE>(parm_open2_rsp->resource_type),
&smb1_subdecoder::send_subflow_premature_end_msg<ntdec_cifs_close_request>,
// ^^^^^^^^^^^^^^^^^
&smb1_subdecoder::send_subflow_premature_end_msg<ntdec_cifs_close_response>);
// ^^^^^^^^^^^^^^^^^
我有一个容器,用于存储包含模板回调的结构。 同时回调签名不包含模板参数。 插入时,出现错误:
cannot convert ‘<unresolved overloaded function type>’ to ‘smb1_subdecoder::send_subflow_premature_end_msg_t’ {aka ‘void (smb1_subdecoder::*)(long unsigned int, unsigned char, long unsigned int, unsigned char)’}
note: initializing argument 4 of
‘void smb1_subdecoder::store_subflow_bunch_on_open(
smb1_subdecoder::handle_t, uint64_t, CIFS_RESOURCE_TYPE,
smb1_subdecoder::send_subflow_premature_end_msg_t,
smb1_subdecoder::send_subflow_premature_end_msg_t)’
send_subflow_premature_end_msg_t send_subflow_premature_end_rq_msg,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
插入代码(此处错误):
store_subflow_bunch_on_open(
handle(response_msg.file_id), response_msg.msg_id,
static_cast<CIFS_RESOURCE_TYPE>(parm_open2_rsp->resource_type),
&send_subflow_premature_end_msg<ntdec_cifs_close_request>,
&send_subflow_premature_end_msg<ntdec_cifs_close_response>);
定义:
存储方式:
void smb1_subdecoder::store_subflow_bunch_on_open(
handle_t handle, uint64_t subflow_msg_id, CIFS_RESOURCE_TYPE resource_type,
send_subflow_premature_end_msg_t send_subflow_premature_end_rq_msg,
send_subflow_premature_end_msg_t send_subflow_premature_end_rsp_msg) { ... }
send_subflow_premature_end_msg_t:
typedef void (smb1_subdecoder::*send_subflow_premature_end_msg_t)
(uint64_t, uint8_t, uint64_t, uint8_t);
用于发送提前结束消息的模板函数(签名不依赖于上述模板参数):
template<class NTDEC_END_OBJECT_T>
void smb1_subdecoder::send_subflow_premature_end_msg(uint64_t subflow_msg_id, uint8_t close_reason,
uint64_t header_msg_id, uint8_t side)
{
NTDEC_END_OBJECT_T end_msg;
_d_smb->proto_fill(end_msg, subflow_msg_id);
end_msg.header_msg_id = header_msg_id;
if (_d_smb->transport() == decoder_smb::TRANSPORT::NETBIOS)
{
const auto* netbios_msg = _d_smb->get_proto_parent<ntdec_object>();
if (netbios_msg)
set_parent_msg_id(end_msg, netbios_msg->msg_id);
}
end_msg.side = (side == -1) ? _d_smb->get_last_data_side() : side;
_d_smb->stream().send_message(end_msg);
}
当 constructing a pointer to member.
时,您必须明确地使用 class 名称限定非静态成员的名称(强调我的)
- If the operand is a qualified name of a non-static member, e.g.
&C::member
, the result is a prvalue pointer to member function or pointer to data member of type T in class C. Note that neither&member
norC::member
nor even&(C::member)
may be used to initialize a pointer to member.
例如
store_subflow_bunch_on_open(
handle(response_msg.file_id), response_msg.msg_id,
static_cast<CIFS_RESOURCE_TYPE>(parm_open2_rsp->resource_type),
&smb1_subdecoder::send_subflow_premature_end_msg<ntdec_cifs_close_request>,
// ^^^^^^^^^^^^^^^^^
&smb1_subdecoder::send_subflow_premature_end_msg<ntdec_cifs_close_response>);
// ^^^^^^^^^^^^^^^^^