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 

specialized constructor arg signitaure for const object

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





PostPosted: Mon Jun 28, 2004 5:46 pm    Post subject: specialized constructor arg signitaure for const object Reply with quote



Hello,

I find that when I am designing a handle class that has an internal
reference to another class that the handle class neither creates or
destroys then I must always provide two versions: a const and a
non-const version. It seems that I could easily avoid this complication
if the language provided a mechanism for specifying a constructor that
is enforced at compile time to be used only when constructing a const
object. The constructor argument signature could be different depening
on whether a const object is being constructed or not. This would allow
the class designer to require that a const reference be passed in when a
const object is being constructed.

One possible option would be to make this distinction by adding const
to the constructor declaration. This would imply that the constructor
argument signature could be used only to construct const objects, and
would *not* imply that the "this" pointer in the constructor was const.

class b;

class a {
a ( b & );
a ( const b & ) const;
}

Thanks for listening.

Jeff


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.