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
?

Reply via email to