1 Star 0 Fork 0

Janisa/GUI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AutoFree.h 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
Janisa 提交于 2024-07-09 19:24 +08:00 . 添加编译工程脚本
#ifndef __AUTOFREE_H__
#define __AUTOFREE_H__
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
template <typename T>
class AutoFree
{
public:
AutoFree(size_t len)
{
Init();
if (len > 0)
{
m_buff = new T[len];
m_len = len;
if (m_buff)
{
memset((void *)m_buff, 0, len * sizeof(T));
}
}
}
AutoFree()
{
Init();
}
AutoFree(T *addr)
{
Init();
m_buff = addr;
}
void Init()
{
m_buff = NULL;
m_len = 0;
}
~AutoFree()
{
if (m_buff)
{
delete[] m_buff;
}
m_buff = NULL;
}
inline T *operator->()
{
return m_buff;
}
inline T *operator=(T *addr)
{
Init();
m_buff = addr;
return m_buff;
}
inline operator T *()
{
return m_buff;
}
public:
size_t m_len;
T *m_buff;
};
#endif // !__AUTOFREE_H__
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Janisa/gui.git
git@gitee.com:Janisa/gui.git
Janisa
gui
GUI
master

搜索帮助