[英]What is `R(*pf)(void*, Args…)`, function pointer to a method?
I saw this type here .我在这里看到了这种类型。 I believe he's trying to create a variable
pf
for a member pointer type-erased (that's why there's void*
there).我相信他正在尝试为类型擦除的成员指针创建一个变量
pf
(这就是为什么那里有void*
)。 I then noticed this type signature in similar such classes.然后我在类似的此类中注意到了这种类型签名。
But according to isocpp a non-static member pointer type is defined like this: int (Fred::*)(char,float)
(for some class Fred
) and a function pointer type is defined like this: int (*)(char,float)
但是根据isocpp ,非静态成员指针类型定义如下:
int (Fred::*)(char,float)
(对于某些 class Fred
)和 function 指针类型定义如下: int (*)(char,float)
Therefore one would create a member pointer variable mp
like this: int (S::*mp)(int) = nullptr;
因此,可以像这样创建一个成员指针变量
mp
: int (S::*mp)(int) = nullptr;
Maybe this void*
represents this*
and its another way to define a member pointer variable by defining a function pointer variable?也许这个
void*
代表this*
及其通过定义 function 指针变量来定义成员指针变量的另一种方式? Is this possible?这可能吗?
What is R(*pf)(void*, Args...)
?什么是
R(*pf)(void*, Args...)
?
It's the declaration of a function pointer.这是 function 指针的声明。 Nothing more than that.
仅此而已。
Compatible functions take void*
and Args...
, and return R
.兼容函数采用
void*
和Args...
,并返回R
。
In the given example, the compatible function that's assigned to the pointer, is a lambda.在给定的示例中,分配给指针的兼容 function 是 lambda。 The
void*
is the type-erased address of some callable f
, and the Args...
members are, well, the arguments that'll be passed to that callable. void*
是一些可调用f
的类型擦除地址,而Args...
成员是 arguments 将传递给该可调用对象。 The callable's type is restored by capturing of type aliases inside the lambda (nice.).通过在 lambda(很好)中捕获类型别名来恢复可调用的类型。
R(*pf)(void*, Args...)
is a function pointer (regular one, not pointer-to-member) to a function that returns R
and has (void*, Args...)
parameters, where Args...
is a list of types (an expanded template parameter pack). R(*pf)(void*, Args...)
is a function pointer (regular one, not pointer-to-member) to a function that returns R
and has (void*, Args...)
parameters, where Args...
是类型列表(扩展的模板参数包)。
Maybe this
void*
representsthis*
and its another way to define a member pointer variable也许 this
void*
代表this*
及其定义成员指针变量的另一种方式
Nah, there is no such feature in C++.不,C++ 中没有这样的功能。
If you look at the code , the only things assigned to this pointer are lambdas, like this one:如果您查看代码,分配给此指针的唯一内容是 lambda,如下所示:
pf = [](void* ptr, Args... args)->R{
return blah;
};
I'm not sure why you expected pointers-to-members to be involved.我不确定您为什么期望指向成员的指针参与其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.