c语言中的变量跟踪法,C++调试追踪class成员变量的方法

比如:int (*foo)(int arg),记住要和另一个指针函数区分开来,类似这样:int *foo(int arg).

比如我们可以这样声明一个变量和函数:

int (*pfun)(int arg)=0;

int fun(int arg);    //这个函数实现随便啦,我就不写了。

如果我们想利用函数指针操作函数,就和指针变量使用一样:

pfun=fun;

int result=(*pfun)(123);

对,很鸡肋也没必要。这是当然,因为我们没用在对的地方。下面我要讲的是利用一个类去call back另一个无关类的成员。

代码:

#include

using namespace std;

template

class Functor{

public:

Functor(T *otherp,N (T::*otherfun)(N arg))

{

mp=otherp;

mfun=otherfun;

}

virtual N operator()(N arg)

{

return (*mp.*mfun)(arg);

}

private:

N   (T::*mfun)(N arg);

T *mp;

};

class A{

public:

A(int a0):a(a0){}

int traced(int b)

{ <

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值