On Monday, 21 November 2022 at 23:41:22 UTC, thebluepandabear wrote:
But why give a C++ code example? 🤨

It's a D code example and it even can't be compiled by a C++ compiler. Just add the missing main function:

```D
void main()
{
  shared c = new Counter;
  c.incrementCounter;

c.count = 12345; // haha, this isn't really private in D (unless the class // is moved to a different module in its own personal file)

  writeln(c.displayCounter);
}
```

The `counter` member variable isn't really protected from rogue accesses (if these accesses are done by the code in the same source file) and this behavior differs from C++.

Reply via email to