Focus

Maxim Fomin maxim at maxim-fomin.ru
Sat Jan 19 05:21:30 PST 2013


On Saturday, 19 January 2013 at 13:12:32 UTC, Andrei Alexandrescu 
wrote:
> On 1/19/13 2:35 AM, Maxim Fomin wrote:
>> On Saturday, 19 January 2013 at 00:11:03 UTC, Adam D. Ruppe 
>> wrote:
>>> On Saturday, 19 January 2013 at 00:04:24 UTC, Andrey wrote:
>>>> So how am I supposed to hide the variable inside the struct 
>>>> or class?
>>>
>>>
>>>> I'm sure "friend" explodes the basics of OOP encapsulation 
>>>> mechanics.
>>>
>>> http://www.parashift.com/c++-faq/friends-and-encap.html
>>>
>>> If you have helper structures it can be useful to get at the 
>>> private
>>> parts anyway, for example an iteration range.
>>
>> http://yosefk.com/c++fqa/friend.html#fqa-14.2
>
> I think that's a rather poor piece.
>
> Andrei

How much chances does this program have?
----------mylib.di--------
class A
{
	public int i;
}

void foo(A a);
---------mylib.d---------
class A
{
	public int i;
	private int ii;
}

void foo(A a)
{
	if (a !is null)
	{
		a.ii = 2;
	}
}
---------main.d---------
import mylib;

void main()
{
	A a = new A;
	a.foo();
}
------------------------
# dmd main.d -c
# dmd mylib.d -c
# gcc main.o mylib.o -lrt -lphobos2 -lpthread
# ./a.out
?


More information about the Digitalmars-d mailing list