Что не так в коде?
Какие изменения я должен внести в код, чтобы сделать его защитным?
Array.h
#ifndef _ARRAY_H_
#define _ARRAY_H_
class Array
{
private:
int * m_ArrayContainer;
public:
Array();
void AllocateMemoryOfSize(int size);
void DeallocateMemory();
void SetElementsIntoTheIndex(int index, int value);
int GetElementFromIndex(int index);
int operator [] (int index);
~Array();
};
#endif
Array.cpp
#include "Array.h"
#include <iostream>
Array :: Array()
{
this->m_ArrayContainer = NULL;
}
void Array :: AllocateMemoryOfSize(int size)
{
this->m_ArrayContainer = new int[size];
}
void Array :: DeallocateMemory()
{
delete [] this->m_ArrayContainer;
}
void Array :: SetElementsIntoTheIndex(int index, int value)
{
this->m_ArrayContainer[index] = value;
}
int Array :: GetElementFromIndex(int index)
{
return this->m_ArrayContainer[index];
}
int Array :: operator [] (int index)
{
return this->m_ArrayContainer[index];
}
Array :: ~Array()
{
this->DeallocateMemory();
}
main.cpp
#include <iostream>
#include "Array.h"
int main()
{
for(int i=0 ; i<250 ; i++)
{
Array array1;
array1.AllocateMemoryOfSize(3);
array1.SetElementsIntoTheIndex(0, 10);
array1.SetElementsIntoTheIndex(1, 10);
array1.SetElementsIntoTheIndex(2, 10);
/*array1.SetElementsIntoTheIndex(0, NULL);
array1.SetElementsIntoTheIndex(1, NULL);
array1.SetElementsIntoTheIndex(2, NULL);*/
array1.DeallocateMemory();
}
}
![enter image description here](https://i.stack.imgur.com/d8XDc.png)