V
Vijay Bajwa
Say I have a const char* msg which is pointing to memory gotten by
something like (msg = new char[100] ). Then if I declare thus:
auto_ptr<const char> smartptr (msg) ;
Then will this bomb royally, when, on destruction, auto_ptr tries to
call delete on msg instead of delete [] ? Well, not bomb, by will
probably only free up 1 char worth of memory?
Is the way around it to make sure you get memory thus?
char* msg = (char*):
perator new (100) ;
if that's the case, and if msg is being returned from a library,
callers must be very sure to call delete and not delete []. Not
elegant, since a pogrammer error like this won't be flagged by a
compiler. Is there a best practise?
Thanks in advance!
Vijay
something like (msg = new char[100] ). Then if I declare thus:
auto_ptr<const char> smartptr (msg) ;
Then will this bomb royally, when, on destruction, auto_ptr tries to
call delete on msg instead of delete [] ? Well, not bomb, by will
probably only free up 1 char worth of memory?
Is the way around it to make sure you get memory thus?
char* msg = (char*):
if that's the case, and if msg is being returned from a library,
callers must be very sure to call delete and not delete []. Not
elegant, since a pogrammer error like this won't be flagged by a
compiler. Is there a best practise?
Thanks in advance!
Vijay