yes they are. Well then there must be something wrong then, cause it works.
yes they are. Well then there must be something wrong then, cause it works.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
well the following code produces 0 as a result
Code:void DeletePtr(void* ptr) { delete ptr; ptr = 0; } int main() { int* t = new int(100); DeletePtr(t); std::cout << t << std::endl; system("pause"); return 0; }
You have an interesting concept of zero.Code:C:\Documents and Settings\Andrew\Desktop>temp 0x3d3d78
Nope, that exact program can never print 0 (except that technically null does not have to equal zero, but we can forget that for the purposes of this discussion as nobody here is using such an architecture). In fact just ran it myself and of course got some random hexadecimal address. Your compiler would have to be completely broken to get a zero out of that.
Perhaps you're seeing the return value from main instead.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
hmm, dunno. I know this one is pretty much guaranteed to work in most cases.
Code:template<class t> void DeletePtr(t*& ptr) { delete ptr; ptr = 0; } template<class t> void DeletePtrA(t*& ptr) { delete []ptr; ptr = 0; }
Well... if you ignore the part after and including the 'x', you did get 0Originally Posted by tabstop
A null pointer constant does evaluate to zero though.Originally Posted by iMalc
Well, now you fixed it to pass the pointer by referenceOriginally Posted by Raigne
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)