如何检查另一个函数调用的函数? [英] How can I check a function was called by another function?

查看:129
本文介绍了如何检查另一个函数调用的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试确保一个类的成员函数仅由另一个类的成员函数调用。



架构是强制的,不能改变,端口意味着在调用 b.call之前,必须在 a.call() a.call()因此调用 b.call()以简化操作并确保顺序符合。 / p>

我发现这个答案我的问题。只有,问题是我使用类,并且这两个类有相同成员函数名,因此 #define 尝试替换所有

解决方案

在我的头顶,选项将是:




  • 使 b.call 私人和make b a >
  • b.call 转换为类,并将正文放入aa的私有构造函数中, a a.call 作为朋友

  • grep源代码 b.call ,确保唯一的调用是 a.call ,并在声明中添加注释如果调用此函数,您将被触发

  • 更改 b.call ,以至少获取一个所需的值参数(即使它忽略它,并使用其他地方的值)


I am currently trying to make sure that a member function of one class is only called by a member function of another class.

The architecture is imposed and cannot be changed, the port means that some logic has to be done in a.call() before calling b.call(). a.call() therefore calls b.call() to simplify things and make sure the order is respected.

I found this answer to my question. Only, the problem is that I am using classes, and the two classes have the same member function name and so the #define tries to replace all the occurrences which have different prototypes.

解决方案

Off the top of my head, options would be:

  • Make b.call private and make b add a or a.call as a friend
  • Turn b.call into a class and put the body into a a private constructor with a or a.call as a friend
  • grep the source code for b.call, make sure the only call is in a.call, and add a comment at the declaration saying "if you call this function you will be fired"
  • Change b.call to take at least one of the values it needs as a parameter (even if it ignores it and uses the value from somewhere else)

这篇关于如何检查另一个函数调用的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆