A
amparikh
Greetings all.
I am sure people here might have written smart pointers in a way that
can handle both a pointer to an object and also a pointer to an array
of objects.
so if you have smart pointer Ptr...
and then you have
Ptr<Element> a( new Element());
Ptr<Element> b( new Element[]());
so how does one differentiate between the two when doing the freeing of
memory...basically differentiating delete and delete[].
I have tried using delete[] on a pointer to single object and it sorta
works, but I know this will cause issues, espeically when someone might
have implemented the operator delete in their class(the class which is
the held pointer in the smart pointer) and I am sure there are other
situations, where this might fail.
Thanks.
I am sure people here might have written smart pointers in a way that
can handle both a pointer to an object and also a pointer to an array
of objects.
so if you have smart pointer Ptr...
and then you have
Ptr<Element> a( new Element());
Ptr<Element> b( new Element[]());
so how does one differentiate between the two when doing the freeing of
memory...basically differentiating delete and delete[].
I have tried using delete[] on a pointer to single object and it sorta
works, but I know this will cause issues, espeically when someone might
have implemented the operator delete in their class(the class which is
the held pointer in the smart pointer) and I am sure there are other
situations, where this might fail.
Thanks.