如何检查另一个函数调用的函数? [英] How can I check a function was called by another function?
问题描述
我目前正在尝试确保一个类的成员函数仅由另一个类的成员函数调用。
架构是强制的,不能改变,端口意味着在调用 b.call之前,必须在
。 a.call()
) a.call()
因此调用 b.call()
以简化操作并确保顺序符合。 / p>
我发现这个答案我的问题。只有,问题是我使用类,并且这两个类有相同成员函数名,因此 #define
尝试替换所有
在我的头顶,选项将是:
- 使
b.call
私人和makeb
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 makeb
adda
ora.call
as afriend
- Turn
b.call
into a class and put the body into a a private constructor witha
ora.call
as afriend
- grep the source code for
b.call
, make sure the only call is ina.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屋!