On Friday, 26 September 2014 at 18:18:45 UTC, Steven Schveighoffer wrote:
On 9/26/14 1:36 PM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schue...@gmx.net>" wrote:

Alternatively, you could create a union with a private and a public member with the same types, but I wouldn't recommend it. Besides, the
members would need to have different names:

    class Foo {
        union {
            private int a;
            public int b;
        }
    }

Hm.. that doesn't provide readonly access to either a or b.

But it gave me an idea:

class Foo {
   union {
      private int _a;
      public const int a;
   }
   void setA(int x) { _a = x; }
}


Yes, that's what I originally intended. Just forgot the const, and didn't even notice it after I reread it :-P

Reply via email to