i am facing problems of destructor in the following code.destructor is not working.can any one help plz????
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class strtype
{
private:
char *p;
int len;
public:
strtype()
{
p=(char *)malloc(sizeof(char));
*p='\0';
len=0;
}
void getString(char *str)
{
len=strlen(str);
p=(char *)realloc(p,sizeof(char)*len);
strcpy(p,str);
}
void showString()
{
cout<<p<<endl;
cout<<strlen(p)<<endl;
}
~strtype()
{
cout<<"freeing p";
free(p);
}
};
int main()
{
strtype s1,s2;
s1.getString("my name is arafat");
s2.getString("jawad votka");
s1.showString();
s2.showString();
return 0;
}