C++学习

C++学习,第1张

C++析构和构造函数学习`

#include "stdafx.h"
#include 
using 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__ }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1295882.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存