在 C++ 中为类的每个函数调用之前运行代码 [英] Run Code Before Every Function Call for a Class in C++

查看:24
本文介绍了在 C++ 中为类的每个函数调用之前运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每次调用一个类的函数以及从该类继承的类的所有函数之前运行一些代码(可能是一个函数).我想在不实际编辑每个功能的情况下做到这一点,这样的事情甚至可能吗?

I would like to run some code (perhaps a function) right before every function call for a class and all functions of the classes that inherit from that class. I'd like to do this without actually editing every function, Is such a thing even possible?

我会满足于在每个函数调用的第一条指令中调用一个函数,而不是在之前调用它.

I would settle for having a function called as the first instruction of every function call instead of it being called right before.

推荐答案

AspectC++ 正是您想要的.我自己没有使用过它,但是 Aspect-Oriented Programming 范式试图解决这个确切的问题问题.

AspectC++ is what you want. I haven't used it myself, but Aspect-Oriented Programming paradigm tries to solve this exact problem.

这篇关于在 C++ 中为类的每个函数调用之前运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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