Original Post
I see alot of people still do this, i consider the following example redundant compared to the latter. Because the standard guarantees that delete pointer will do nothing if pointer is equal to 0. Now for the reason i'm posting here, I simply dont trust my memory [rolleyes], haven't touched a line of code since may or so. So if anyone could clarify if the standard does indeed promise that no action will be taken if a pointer is 0, rather shure this holds true but better safe than sorry. Also if you use the first case, why? [grin] Edit: minor bugfixes [Edited by - monkeyCode on September 13, 2005 8:32:32 PM]
struct Data { ... };
class Object {
public:
Object() : data(0) {
data = new Data;
}
~Object() {
if(data) {
delete data;
data = 0;
}
}
protected:
Data* data;
};
struct Data { ... };
class Object {
public:
Object() : data(0) {
data = new Data;
}
~Object() {
delete data;
}
protected:
Data* data;
};