First: You misunderstood the meaning of the word "dereference"
Dereferencing means getting a value of the pointer by using a "*" operator. For example:
qDebug() << *obj; // <-- this is a dereferencing of the "obj" pointer
QObject *obj = new QObject;
qDebug() << *obj; // <-- this is a dereferencing of the "obj" pointer
To copy to clipboard, switch view to plain text mode
Second: Guessing that you asked if it is needed to assign 0 to the pointer after object has been deleted, the answer is: this is handy if your pointer can be potentially used in other places in code (for example if it is a member of some class). In these situations you can check if that object is already deleted. And delete or deleteLater doesn't make difference: Assigning 0 is used only to be able to tell if that ptr still exists or not. Examples:
void myFunction()
{
MyClass* obj = new MyClass;
// some action...
delete obj;
// obj = 0 <-- doesn't make sense, function will end and no one will ever know about obj as it is a local variable
}
void myFunction()
{
MyClass* obj = new MyClass;
// some action...
delete obj;
// obj = 0 <-- doesn't make sense, function will end and no one will ever know about obj as it is a local variable
}
To copy to clipboard, switch view to plain text mode
class SomeClass
{
private:
public:
void func1()
{
// some action
delete m_obj;
m_obj = 0;
}
void func2()
{
// try to use m_obj, but check if it really exists
if( m_obj )
// do some stuff
else
qDebug() << "oops, m_obj is already deleted";
}
}
class SomeClass
{
private:
QObject* m_obj;
public:
void func1()
{
m_obj = new QObject;
// some action
delete m_obj;
m_obj = 0;
}
void func2()
{
// try to use m_obj, but check if it really exists
if( m_obj )
// do some stuff
else
qDebug() << "oops, m_obj is already deleted";
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks