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 

pointer to reference conversion

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
toton
Guest





PostPosted: Thu Sep 14, 2006 9:10 am    Post subject: pointer to reference conversion Reply with quote



Hi,
This is continuation of topic pointer & reference doubt.
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/df84ce6b9af561f9/76304d7d77f6ccca?lnk=raot#76304d7d77f6ccca
But I think it is better to have a new topic rather than continuing on
old one.

As now I am sure pointer to reference and reference to pointer are
freely convertable, the potential danger lies in the first one. Pointer
may be NULL, but reference should not be.
My question is, what is the best way to answer it?
just assert that the pointer is not NULL, before dereferencing it?
However that will lead to a debug only checking. In the post
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/61047ec3cb284b4/a6d52926a25a167c?lnk=gst&q=frederick&rnum=3#a6d52926a25a167c
Frederick Gotham had suggested an alternative method in some different
context, which throws an exception. Thus I think it is valid even at
non-debug mode and catches such potential problem at runtime.

Which one should be preferred? and any one deals with this conversion
problem in some standard way?
Going a little further, like the new operator is written throw a
bad_alloc, so one need not to check NULL pointer afrer a new (and one
can overload global new as well as specific new according to his
convenience to have some specific handler also) , can the dereferencing
operator be overloaded (globally and class specific way) to throw some
exception when one is dereferencing a NULL pointer?
Ofcouse the danger will not be fully eleminated (as one can have a
pointer which is not NULL, but points to some invalid object, like
dereferencing a pointer after delete. But such problem can be handled
with a safe_delete which sets the pointer to NULL. Or also in
conjugation with nullptr
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1488.pdf ),
but it will get significantly removed.
Looking for some suggestions and expert comments.

Thanks
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) 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.