Leak memory.Can anyone help me!


#include<iostream>
using namespace std;
#ifdef _DEBUG

// test memory leak
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>

// UIDEBUG_DUMPLEAK
// In danh sach Memory bi LEAK
#define UIDEBUG_DUMPLEAK() _CrtDumpMemoryLeaks()
#else
#define UIDEBUG_DUMPLEAK()
#endif
template<class T>class Array
{
T *mang;
int size;
public:
Array(int n);
~Array();
void setValue(T n,int vitri);
void makeArray(T*&arry,int n);
T &operator[](int i);
int seek(T &key);
int search(T *list,int size,T key);
};
template<class T> Array<T>::Array(int n)
{
size=n;
mang=new T[size];
}
template<class T> Array<T>::~Array()
{
cout<<"Destructor"<<this<<endl;
delete []mang;
}
template<class T> void Array<T>::setValue(T n,int vitri)
{
*(mang+vitri)=n;
}
template<class T> void Array<T>::makeArray(T *&m, int n)
{
m=new T[n];
}
template<class T> T &Array<T>::operator[](int i)
{
return mang[i];
}
template<class T> int Array<T>::seek(T & key)
{
int index=0;
while(index<size && mang[index]!=key)
index++;
if(index==size)
return -1;
else
return index;
}
template<class T> int Array<T>::search(T *list,int kt,T key)
{
int index=0;
while(index<kt && list[index]!=key)
index++;
if(index==kt)
return -1;
else
return index;
}
class person
{
int age;
public:

person()
{
cout<<"COnstructor"<< this<<endl;
age=0;
}
person(int n)
{
cout<<"Constructor with argument"<<this<<endl;
age=n;
}
int getage()const
{
return age;
}
friend bool operator !=(person p1, person p2)
{
return p1.getage()!=p2.getage();
}
friend ostream &operator <<(ostream &os,const person &p)
{
os<<p.getage()<<endl;
return os;
}
};


void main()
{
Array<person> a(3);
UIDEBUG_DUMPLEAK();
}


To see leak memory press f10 to debug, see output.I use visual studio 2010.
Thank for any advice or help
I can't really read your code as it's not indented. Your Array class doesn't have a copy constructor and assignment operator and it should, but they're not being called so they haven't caused a problem yet.

You should realise that ~Array<person> is called after the call to UIDEBUG_DUMPLEAK. I don't think you have a leak.
Thanks.
Topic archived. No new replies allowed.