On Sunday, 28 January 2024 at 04:47:30 UTC, FairEnough wrote:

module test;
@safe:

import std;

        class C
        {
private(this) int x; // intent: other code in this module cannnot mutate this. private(this) int y; // intent: other code in this module cannnot mutate this.

            invariant () { assert (x == y); }

            void modifyX() {...}
            void modifyY() {...}
        }


        void foo(C c)
        {
            c.x = 10; // compiler will not compile this code.
            c.modifyX();
        }

Thank you for posting a very informative example, i think not just myself but everyone else on this forum had completely forgot how class private is supposed to work. In spite of the 1000 or so posts you've made about it.

Keep up the good work!

Reply via email to