__FUNCTION__ 宏表示当前所在函数名;

__FILE__ 宏表示当前所在文件路径;

__LING__ 宏表示当前所在行;

利用对象离开函数时调用析构函数销毁的特点,打印出函数执行结束的信息

 

代码:

#include <iostream>
#include <cstdio>

class FunctionCallLogger
{
public:
    FunctionCallLogger(const char* functionName)
    {
        strcpy(m_functionName, functionName);
        printf("%s:  %s Enter!   line:%d \n", __FILE__, m_functionName, __LINE__);
    }
    ~FunctionCallLogger()
    {
        printf("%s   %s Leave!   line:%d \n", __FILE__, m_functionName, __LINE__);
    }
private:
    char m_functionName[256];
};
#define LOG_FUNCTIONCALL FunctionCallLogger(__FUNCTION__);

int main()
{
    LOG_FUNCTIONCALL
    return 0;
}

相关文章:

  • 2021-12-24
  • 2021-11-04
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-10-06
猜你喜欢
  • 2021-06-23
  • 2021-11-15
  • 2021-10-30
  • 2022-02-09
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案