Destroy also set NULL ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Destroy also set NULL ?

Post by Marcus Frenkel » Tue Jun 01, 2010 11:19 pm

Excuse me for this simple question, I couldn't find the answer in the forum already.

When wxWindow or derived class is destroyed is the pointer set to NULL as well.

Ex:

Code: Select all

wxScrolledWindow * scwin = new wxScrolledWindow(...);
..
..
scwin->Destroy(); //is scwin nulled after this or scwin=NULL; must be called "manually"?
..
..
if (scwin != NULL) ...
Marcus

User avatar
doublemax
Moderator
Moderator
Posts: 15507
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Tue Jun 01, 2010 11:47 pm

It's impossible that the called method sets the pointer to NULL, so: No.
Use the source, Luke!

Virchanza
Experienced Solver
Experienced Solver
Posts: 78
Joined: Sun Jul 19, 2009 6:12 am

Post by Virchanza » Wed Jun 02, 2010 1:29 pm

If you create a local variable within a function, there's only 2 ways that the variable can be altered from outside of that function:
1) If you pass the variable's address to another function
2) If you pass the variable by reference to another function

(It's possible that you could use a preprocessor macro that disguises the fact that it's passing the variable's address to another function).

What you describe could only be made possible if the constructor for the wxScrolledWindow class took as an argument the address of the variable you use to store the address of the wxScrolledWindow object, something like:

Code: Select all

class wxScrolledWindow {

protected:

    wxScrolledWindow **where_my_address_is_stored;

public
    wxScrolledWindow(wxScrolledWindow **p)
    {
        where_my_address_is_stored = p;
    }

    ~wxScrolledWindow()
    {
        *where_my_address_is_stored = 0;
    }
};
Then, from within your own code, you've have to create a wxScrolledWindow something like:

Code: Select all

wxScrolledWindow *p = new wxScrolledWindow(&p);
This would be a dangerous setup though, because you would have to be careful though that the "p" variable is still in scope when the wxScrolledWindow object is destroyed (which probably won't be the case if the "p" variable is a local variable within a function).

Post Reply