Object Deletion: use parent or not
Posted
by metdos
on Stack Overflow
See other posts from Stack Overflow
or by metdos
Published on 2010-05-04T11:25:50Z
Indexed on
2010/05/04
11:48 UTC
Read the original article
Hit count: 216
Which one do you prefer to delete objects? Especially in QT, but other practices are also welcome. These two alternatives seem same to me, are they?
1.Bound to another class, and destroy when it is destroyed.
SomeClass::SomeClass{
socket_ = new QTcpSocket(this);
}
or
2.Destroy in the destructor of class
SomeClass::SomeClass{
socket_ = new QTcpSocket();
}
SomeClass::~SomeClass{
delete socket_;
}
© Stack Overflow or respective owner