[英]Explicit passing “this” parameter to method call
Is it possible in c++ call class method with explicit passing first "this" param to it? 是否有可能在c ++调用类方法中显式传递第一个“this”参数呢?
Something like this: 像这样的东西:
struct A
{
void some() {}
};
....
A a;
A::some(&a); // ~ a.some();
For reasonable question "WHY?": i need to implement std::bind analogue, and it works fine with constructions like this: 对于合理的问题“为什么?”:我需要实现std :: bind analogue,它适用于这样的结构:
void f(int);
bind(f, 3);
but this doesn't work: 但这不起作用:
bind(&A::some, &a);
UPDATE: Guys, my question is obviously not really clear. 更新:大家好,我的问题显然不是很清楚。 I know how to use std::bind, i want to know HOW is it processing constructions where this param explicitly passed to it: std::bind(&A::some, &a); 我知道如何使用std :: bind,我想知道如何处理这个param显式传递给它的构造:std :: bind(&A :: some,&a);
Here is an idea for a dispatcher which you could use inside your bind
: 以下是您可以在bind
使用的调度程序的想法:
template <class R, class... Arg>
R call(R (*f)(Arg...), Arg &&... arg)
{ return f(std::forward<Arg>(arg)...); }
template <class C, class R, class... Arg>
R call(R (C::*f)(Arg...), C &c, Arg &&... arg)
{ return (c.*f)(std::forward<Arg>(arg)...); }
Do you want something like the following ? 你想要下面这样的东西吗?
struct A
{
void some();
static void some(A* that) { that->some(); }
};
..
A a;
A::some(&a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.