From 3583128778306239715 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,df06663c0326d841 X-Google-Attributes: gid109fba,public X-Google-Thread: f78e5,df06663c0326d841 X-Google-Attributes: gidf78e5,public From: sbnaran@localhost.localdomain (Siemel Naran) Subject: Re: auto_ptr copy semantics Date: 1999/04/18 Message-ID: #1/1 X-Deja-AN: 467928579 Approved: Fergus Henderson References: <7el5br$kjj$1@nnrp1.dejanews.com> <7f0i8a$sc9$1@nnrp1.dejanews.com> <7f5bhs$vgm$1@nnrp1.dejanews.com> X-Original-Date: 16 Apr 1999 18:23:46 GMT X-Complaints-To: news@news.unimelb.edu.au X-Trace: izvestia.its.unimelb.edu.au 924441443 2863 128.250.29.16 (18 Apr 1999 13:17:23 GMT) Organization: University of Illinois at Urbana-Champaign X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANxnbSuEDnX0m9pzZAQGRxQF/buob3X3cJzEuwJ0TAB7JylKIC8a4XDrL CHzMsoDgl823fovW9jLWssC9oqYY/6vl =IUmQ Reply-To: sbnaran@uiuc.edu NNTP-Posting-Date: 18 Apr 1999 13:17:23 GMT Newsgroups: comp.lang.c++,comp.std.c++ On 16 Apr 99 07:15:45 GMT, sirwillard@my-dejanews.com >Use of an auto_ptr as _documentation_, especially in the case of passing to a >function, is poor documentation. *shrug* In any event, I've seen lots of >discussion regarding use of auto_ptr on a return, but none on passing an >auto_ptr. This, to me, is indication enough of the rarity of the need. I >fully concede there's a use for it, and did so in the quote above. I just >don't buy that's it's use is or should be frequent, and I surely wouldn't use >it just to "document" the passage of ownership. Further, you assert that >it "enfoces" ownership and thus reduces error. I'd contend that it causes as >many errors as it prevents, and that "tracking ownership manually" is still >required. Using std::auto_ptr to document the passage of ownership is a great idea if the pointer to the object is stored. This quickly tells the client who is responsible for deleting the object. Example: class Map { public: Map(); ~Map(); //void add_object (Graph_Object *); // Conceptual error: // Who deletes the "Graph_Object *" // Does class Map delete it? As in: // int main() { Map m; m.add_object(new Graph_Object()); } // Or does something else delete it? As in: // int main() { Map m; Graph_object g; m.add(&g); } // It seems that the first option is more common, so how about void add_object (std::auto_ptr); private: std::list all_objects; }; -- ---------------------------------- Siemel B. Naran (sbnaran@uiuc.edu) ---------------------------------- --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]