Home » U++ Library support » U++ Core » calling delete on pointer
calling delete on pointer [message #52334] |
Tue, 10 September 2019 06:18 |
|
Hi all-
I am trying to figure out why the smart pointers are handy.
I called delete on a smart pointer and unless I specifically
set it to NULL after I call delete it doesn't return NULL
with the T * operator->() method.
I'd like my code to be able to detect that the smart pointer
is NULL.
I am not sure I understand the advantage if after I call delete
that it doesn't detect that delete has been called.
Here is the offending code:
Thanks for any cool help:
struct Foo: Pte<Foo> {
String s1;
Foo * f4;
Foo() {
s1 = String() << "Hello Jim";
}
String & myfunc () {
return s1;
}
Foo * operator-> () {
return f4;
}
};
GUI_APP_MAIN
{
Foo * f = new (Foo) ;
String str = f->myfunc();
delete f;
if (!f->operator->())
PromptOK("null");
else
PromptOK(str);
|
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 16:03:57 CET 2024
Total time taken to generate the page: 0.01511 seconds
|