弱逼问题:S::*xmeth是个啥? S是个类吧,xmeth是类的一个成员?成员能当做变量类型吗?
贴上相关代码
template<class S, class A1, class A2, class R> void
rpcs::reg(unsigned int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
R & r))
{
class h1 : public handler {
private:
S * sob;
int (S::*meth)(const A1 a1, const A2 a2, R & r);
public:
h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, R & r))
: sob(xsob), meth(xmeth) { }
int fn(unmarshall &args, marshall &ret) {
A1 a1;
A2 a2;
R r;
args >> a1;
args >> a2;
if(!args.okdone())
return rpc_const::unmarshal_args_failure;
int b = (sob->*meth)(a1, a2, r);
ret << r;
return b;
}
};
reg1(proc, new h1(sob, meth));
}
贴上报错信息
贴上相关截图
已经尝试过哪些方法仍然没解决(附上相关链接)
According to template parameters
It can be seen that
CanS
,A1
,A2
andR
are all classes. So,No, the type of the third parameter of function
reg
is member function pointer, not a member.Specifically, the variable name of the third parameter of function
reg
ismeth
and the type isint (S::*)(const A1, const A2, R &)
. That is,meth
is a pointer to a member function of classS
. The member function of this classS
has three parameters. The types of these three parameters areconst A1
,const A2
andR &
respectively. This The return value type of member functions of typeS
isint
.might be easier to understand in English:
meth
is a pointer points to member function of classS
whose parameters areconst A1
,const A2
andR &
, return type isint
.If you don’t understand it well, you can learn it first How to read function pointer, you can also use the cdecl website.
This is a member function pointer. Generally speaking, the length ranges from 4byte to 16byte. Internally, according to different ABI conventions, it describes the calling addressing method of member functions given a class pointer. I look at your class. There is also an S* member. This class should be a wrapper for class member functions
The calling method in your code is like this (sob->*meth) (parameter)