specialized constructor arg signitaure for const object

J

Jeff Hill

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,941
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top