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
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