"Peter Dimov"
From: "Alan M. Carroll, CodeSlinger"
operator void const * () const { return px; }
delete ptr; // ;-)
In the general case unwanted comparisons are a problem, too.
According to (an admittedly old) spec (Annotated C++), 5.3.4 says "A pointer to constant cannot be deleted" in reference to the delete operator. Since the value returned by this operator is a pointer to constant void, the statement you have should generate a compiler error. I've tested in on MS-VC 6 (SP5) and it does not compile. int main(int argc, char **argv) { void const * ptr; delete ptr; return 0; } yields error C2664: 'delete' : cannot convert parameter 1 from 'const void *' to 'void *' What kind of unwanted comparisons can occur? The ability to compare directly to a raw pointer seems like a feature. It would seem that this just allows the same comparisons one would get with a raw pointer, which makes shared_ptr easier to drop in as a replacement.