how to make private class member private

Nick Treleaven nick at geany.org
Thu Mar 29 09:48:09 UTC 2018


On Sunday, 18 March 2018 at 18:45:23 UTC, Steven Schveighoffer 
wrote:
> unittest
> {
>    auto foo = new Foo;
>    assert(foo.internalbuffer.empty); // note, this is a private 
> symbol.
> }

I don't understand why you would want a private symbol in a 
*documented* unittest, the reader of the *documentation* will not 
be able to run the example code.

> I can do the same thing in ddoc, but without the benefit of 
> having the unit test run.

You mean not using a unittest?

> Forcing me to do it that way is just annoying (I will have to 
> duplicate the code).

If you really want your documented unittests not to be runnable 
by a user, you can have a free function with `protected` access 
as a workaround.


More information about the Digitalmars-d-learn mailing list