Delete keyword and Destructor problem
Hi..
I have misunderstanding with delete keyword, specially with data structures programming, in the following code, does i have to delete the dynamic prt, or it will destruct automatically,
Please explain what is happen??
and thank you in advance
Code:
#include "iostream"
using namespace std;
template <class T>
class A
{
private:int *ptr;
public:
A(){
int *ptr=new int(9);
cout<<"\nAAA\n";
}
~A()
{
cout<<"D "<<" ";
delete ptr;
}
};
void main()
{ A<int> a11;
}
"this code doesn't work properly"