The code below is working fine but i would like to know that the representation of destructor is correct way or not?? I think it would be sort of recursion in line "delete p" in ~myclass() destructor?
You mean that by deleting the p in myclass you might delete the p in main? If that's the case then no, there's no problem. The p in main is different from p[1].p
You do however have a memory leak, since you don't deallocate the memory for name in myclass' destructor
By the way, this is the first time I see a destructor being explicitly called. I didn't even know it would compile...
Do not do this. Never call the destructor explicitly unless the object was created through placement "new". The reason why you should not call the destructor is because the compiler will implicitly call the destructor for you. If you call the destructor, the compiler will still call the destructor regardless, thereby destroying an invalidated object -- not good.
in the above code the line p = new myclass[3] is going to create object through "new" if i am not wrong.
"If you call the destructor, the compiler will still call the destructor regardless, thereby destroying an invalidated object."
I am not able to getting you. even if here i have created object with new.
So why should we do not call destructor explicitly in this case? If so then, Is there any other way to destruct the one element of the array and not the entire array?