|
Boost : |
From: Andrew D Jewell (ajewell_at_[hidden])
Date: 2000-03-13 10:57:34
>You seem to be confused between a pointer that is const and a pointer that
>points to an object that is const.
>
>Your proposal seems to blur and mix these.
Yes, exactly.
I suppose I could have given a slightly better example, so I've
included one below. When I have a pointer in a class, I often want
the const methods of the class to pass the constness through to the
pointed-to members. I realize that this is NOT the behavior of a
naked pointer. Sometimes I write classes where a change to a
pointed-to object would change the observable state, and therefore I
want the constness passed through. I know there are many uses where
you would NOT want the constness passed through, I just haven't
needed them yet.
An alternate solution, would be to make all of the original six
classes be Qualified, and make the user explicitly say "mutable" if
they don't want the constness passed through.
Andy Jewell
P.S. As I was writing this, Steve's message came through. Thanks for
the excellent clarification.
class qualified_scoped_ptr {
T * operator -> () throw() { return p; }
const T * operator -> () const throw() { return p; }
}
class scoped_ptr {
T * operator -> () const throw() { return p; }
}
class X {
void f();
};
class Y {
scoped_ptr<X> spx;
qualified_scoped_ptr<X> qspx;
mutable qualified_scoped_ptr<X> mqspx;
void g() const();
}
void Y::g() const
{
spx->f(); // OK
qspx->f(); // compile error (or warning) : non-const method on
const object.
mqspx->f(); // also OK
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk