计算对类函数的所有调用次数
Count number of all calls to a class function
我有这样的类:
class Handler : public QObject
{
Q_OBJECT
public:
explicit Handler(Scene *scene, QObject *parent = nullptr);
~Handler();
void runTests(const QVector<Test> *tests);
private:
Scene *m_scene; // parent, not owned
const QVector<Test> *m_tests; // Not owned, set by others
};
runTests
函数为:
void Handler::runTests(const QVector<Test> *tests)
{
if (tests->isEmpty()) {
return;
}
m_tests = tests;
// ... do things ...
return;
}
我打算计算从类实例化的任何对象对runTests
函数的调用次数Handler
。我很困惑如何使用static
成员来做到这一点。有人可以帮忙吗?
如果Handler
怎么称呼它并不重要,那么static
就是要走的路。 您可以将static
成员作为私有变量放在类中,或者只是将其放在函数中。
void Handler::runTests(const QVector<Test> *tests)
{
static size_t _numTimesCalled = 0;
++_numTimesCalled;
if (tests->isEmpty()) {
return;
}
m_tests = tests;
// ... do things ...
return;
}
相关文章:
- 使用宏调用类函数
- Python在不引用类名的情况下调用类函数
- 从 LUA 脚本调用类函数C++
- 在定义变量时调用类函数
- 你如何调用类函数,但使用不同的类对象
- 从构造函数调用类函数或使用智能指针
- 在 c++ 中通过指针从另一个类调用类函数
- 加载cygwin C++dll,调用类函数
- 不能调用类函数(参数化类)
- c++从非成员调用类函数/数据
- 通过信号和时隙系统调用类函数
- C++:在交换机中调用类函数
- 在 main 中调用类函数
- 不确定如何使用模板调用类函数
- C++ 调用类函数作为回调
- 通过此指针从静态函数调用类函数
- 从Vector而不是Array调用类函数
- 线程调用类函数时出错
- C++类继承,用指针调用类函数
- 从另一个类调用类函数