encapsulation

torhu fake at address.dude
Tue Mar 13 13:44:28 PDT 2007


BCS wrote:
> If I understand correctly, the idea is to get rid of friend but still let 
> some things look inside of others. This solution lets closed set of code 
> interact at a low level while doing encapsulation at wider scopes. The reason 
> friend is discarded is that it has the power to do arbitrary snooping which 
> causes the same kind of problems as goto's arbitrary redirection causes.

'friend' doesn't work they way you're implying here.

 From Stroustrup himself, at 
http://www.research.att.com/~bs/bs_faq2.html#friend

---
Does "friend" violate encapsulation?
No. It does not. "Friend" is an explicit mechanism for granting access, 
just like membership. You cannot (in a standard conforming program) 
grant yourself access to a class without modifying its source. For example:

	class X {
		int i;
	public:
		void m();		// grant X::m() access
		friend void f(X&);	// grant f(X&) access
		// ...
	};

	void X::m() { i++; /* X::m() can access X::i */ }

	void f(X& x) { x.i++; /* f(X&) can access X::i */ }
---



More information about the Digitalmars-d mailing list