P
pauldepstein
On page 82 of Effective C++, an example of non-compilable code is given
as follows:
std::tr1::shared_ptr<Investment>
pInv(0, getRidOfInvestment);
I understand this part -- 0 is not a valid parameter for pInv because 0
is an int and not a pointer.
Here is the text's intended correction:
std::tr1::shared_ptr<Investment>
pInv( static_cast<Investment*>(0),
getRidOfInvestment);
I understand why this works. Here's what I don't understand --
Wouldn't a simpler correction be to use pInv(NULL, getRidOfInvestment);
If the problem is that 0 is not a pointer, why not use the intended
NULL pointer. Isn't NULL a pointer? My correction seems clearer, and
this leads me to suspect that I might be missing something.
Thank you.
Paul Epstein
as follows:
std::tr1::shared_ptr<Investment>
pInv(0, getRidOfInvestment);
I understand this part -- 0 is not a valid parameter for pInv because 0
is an int and not a pointer.
Here is the text's intended correction:
std::tr1::shared_ptr<Investment>
pInv( static_cast<Investment*>(0),
getRidOfInvestment);
I understand why this works. Here's what I don't understand --
Wouldn't a simpler correction be to use pInv(NULL, getRidOfInvestment);
If the problem is that 0 is not a pointer, why not use the intended
NULL pointer. Isn't NULL a pointer? My correction seems clearer, and
this leads me to suspect that I might be missing something.
Thank you.
Paul Epstein