Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » calling delete on pointer
calling delete on pointer [message #52334] Tue, 10 September 2019 06:18 Go to next message
mtdew3q is currently offline  mtdew3q
Messages: 181
Registered: July 2010
Location: Upstate, NY (near Canada)
Experienced Member

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);

Re: calling delete on pointer [message #52335 is a reply to message #52334] Tue, 10 September 2019 08:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Pte/Ptr are supposed to solve different problem:

Ptr<Foo> ptr;
{
   Foo x;
   ptr = &x;
}
ASSERT(!ptr);


In other words, the mechanism is supposed to make Ptr NULL when the object that is pointed to by it is destroyed.

Mirek
Re: calling delete on pointer [message #52337 is a reply to message #52334] Tue, 10 September 2019 14:38 Go to previous message
mtdew3q is currently offline  mtdew3q
Messages: 181
Registered: July 2010
Location: Upstate, NY (near Canada)
Experienced Member

Hi mirek,

Thanks!

Jim
Previous Topic: SHA1 Doesn't work any more for data over 65536 bytes
Next Topic: SetVppLogNoDeleteOnStartup() declaration is missing
Goto Forum:
  


Current Time: Fri Mar 29 16:03:57 CET 2024

Total time taken to generate the page: 0.01511 seconds