yes they are. Well then there must be something wrong then, cause it works.
Printable View
yes they are. Well then there must be something wrong then, cause it works.
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.
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 0 :DQuote:
Originally Posted by tabstop
A null pointer constant does evaluate to zero though.Quote:
Originally Posted by iMalc
Well, now you fixed it to pass the pointer by reference ;)Quote:
Originally Posted by Raigne