int *mas=new int[5];
...
delete[] mas;
mas = 0;
class CMy
{
protected:
int *m_piMas;
public:
CMy();
virtual ~CMy();
bool Create(unsigned int iSize);
void Clear();
bool Get(int idx, int &iData);
bool Set(int idx, int iData);
};
CMy::CMy()
{
m_piMas = NULL;
}
CMy::~CMy()
{
Clear();
}
bool CMy::Create(unsigned int iSize)
{
Clear();
m_piMas = new int[iSize];
return (NULL != m_piMas);
}
void CMy::Clear()
{
if(m_piMas)
{
delete[]m_piMas;
m_piMas = NULL;
}
}
bool CMy::Get(int idx, int &iData)
{
if(m_piMas)
{
iData = m_piMas[idx];
return true;
}
return false;
}
bool CMy::Set(int idx, int iData)
{
if(m_piMas)
{
m_piMas[idx] = iData;
return true;
}
return false;
}
int *mas=new int[iSize];
delete[]mas;
#ifdef _DEBUG
#include <crtdbg.h>
#endif
int main()
{
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF|_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
#endif
const int SIZE=10;
// Выделяем память
int* arr=new int[SIZE];
// Что-то делаем
for(int i=0;i<SIZE;++i)
{
arr[i]=i;
}
// Забыли освободить
// delete[] arr;
}
...
Detected memory leaks!
Dumping objects ->
{68} normal block at 0x00757DD8, 40 bytes long.
Data: < > 00 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00
Object dump complete.
Программа "[4880] 187140.exe" завершилась с кодом 0 (0x0).
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.