Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!fernwood!lia!jgro From: jgro@lia (Jeremy Grodberg) Newsgroups: comp.lang.c++ Subject: Deleting smart pointers Message-ID: <1991Apr12.064819.10047@lia> Date: 12 Apr 91 06:48:19 GMT Reply-To: jgro@lia.com Distribution: usa Organization: Litton/Integrated Automation, Alameda CA Lines: 37 I have a class of smart pointers, and have most of what I want working, but I'm stumped on one thing: deleting the objects they point to. For a regular pointer, you do something like this: int* foo = new int(0); // do something delete foo; I'd like to mimic that with SmartPointer foo = new Smart(0); // do something delete foo; The only way I see to do that, though, is to declare a delete operator for the class SmartPointer which assumes the void* passed to it is in fact a pointer to a SmartPointer, and deletes the real pointer inside the SmartPointer class. This is really quite an abuse of the rules, and I'd like a cleaner way. Currently, I am resorting to an explicit function call to delete the object: //Want to "delete foo", but can't use that syntax foo.deleteElem(); //can't even call the function "delete", since its reserved This is annoying because it adds an extra burden on the programmer to remember which type of pointers they are dealing with. Any suggestions? -- Jeremy Grodberg "Show me a new widget that's bug-free, and I'll show jgro@lia.com you something that's been through several releases."