C++析构和构造函数学习`
#include "stdafx.h" #includeusing namespace std; class MyClass { public: MyClass(); ~MyClass(); MyClass(const char *funcDebug_, const char *func_); private: const char *funcDebug_{ nullptr }; //成员变量带下划线 const char *func_{ nullptr }; }; MyClass::MyClass() { } MyClass::~MyClass() { cout << funcDebug_ << " MyClass, leave" << endl; } //初始化参数列表 MyClass::MyClass(const char *funcDebug_, const char *func_) :funcDebug_{ funcDebug_ }, func_{ func_ } { cout << funcDebug_ << " MyClass, inter" << endl; } //宏定义 类对象 #define CALL_LOG_ENTER MyClass ___MyClass___ { LABEL, nullptr } const char *LABEL = "Label"; int _tmain(int argc, _TCHAR* argv[]) { CALL_LOG_ENTER; return 0; } 模仿的代码:鸿蒙学习 namespace OHOS { namespace MMI { class InnerFunctionTracer { public: InnerFunctionTracer(const OHOS::HiviewDFX::HiLogLabel& label, const char *func) : label_ { label }, func_ { func } { OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, enter", func_); } ~InnerFunctionTracer() { OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, leave", func_); } private: const OHOS::HiviewDFX::HiLogLabel& label_; const char* func_ { nullptr }; }; } // namespace MMI } // namespace OHOS #define CALL_LOG_ENTER InnerFunctionTracer ___innerFuncTracer___ { LABEL, __FUNCTION__ }



