On 2005-11-28,
po******@gmail.com <po******@gmail.com> wrote:
Is it possible to declare a const friend or something. I wish
to make class B friend of class A but I don't want it to be
changing A. It's a read-only friend. Is this possible?
Include an in-between friend that provides the access for the
members you want to share.
class A {
int x, y;
friend class B;
};
class B {
const int &x() const { return A::x; }
const int &y() const { return A::y; }
/* If they're really built-in types, you wouldn't necessarily use
references. But in general, you would. */
friend class C;
};
class C {
// Must use B::x() and B::y() to access A::x and A::y.
};
--
Neil Cerutti