C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Marking pointer ownership semantics

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Peter Dimov
Guest





PostPosted: Tue Aug 17, 2004 11:43 pm    Post subject: Re: Marking pointer ownership semantics Reply with quote




[email]cdiggins (AT) videotron (DOT) ca[/email] ("christopher diggins") wrote in message news:<kZ9Uc.56580$sk2.829133 (AT) wagner (DOT) videotron.net>...
Quote:
In my programming language Heron, I have mark pointer ownership semantics
using an extra symbol. It occured to me that this might be something worthy
of consideration for C++.

The motivation is essentially this, when a function acts as an object
factory we rely on a naming convention or other form of documentation to
indicate to the user of that function that the responsibility for deletion
of the object is being tranfserred to the owner.

Consider the following example:

AbstractIterator* SomeCollectionClass::CreateRunTimeIterator() {
return new AppropriateConcreteIterator;
}

This function is flawed, since it returns an unmanaged resource. It
should return auto_ptr, shared_ptr, or another smart pointer or
handle, as appropriate.

[...]

Quote:
We could in C++ introduce a special kind of pointer, say MyObject^ which was
distinguishable from MyObject* in that it could only be initialized or
assigned from anything but another owner pointer or the results of a new
operation.

There is a certain appeal to new returning a special kind of pointer.
However if we could change the return type of new X (we can't, really,
it will break too much existing code), what's wrong with auto_ptr<X>?

Quote:
http://www.heron-centric.com

You ask some interesting questions in The Joel on Software forum. Too
bad I don't read it. Wink Without going too off-topic (this is c.s.c++
after all):

http://boost.org/libs/smart_ptr/sp_techniques.html#weak_without_shared

may give you some ideas about weak pointers to stack objects.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

[ 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://www.jamesd.demon.co.uk/csc/faq.html ]



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.