Re: Is this expected? default to public members in private class

2015-05-04 Thread Dan Olson via Digitalmars-d-learn
ketmar ket...@ketmar.no-ip.org writes:

 On Sun, 03 May 2015 18:07:20 -0700, Dan Olson wrote:

 It seems a private class or struct defaults to public members.  Just
 curious if this is intended.  I would have expected private all the way
 down unless overriden.

 i bet it is intended. protection of struct/class members is independed of 
 protection of struct/class itself. this is good for code consistency: no 
 changing of outer protection flags can alter struct/class inner 
 machinery. so if you changed your mind about protection level of some 
 global things, you shouldn't unnecessary fix your code in completely 
 unrelated places.

Thanks ketmar, that makes sense.  I am in midst of adding an option to
have dscanner skip private/package declarations when emitting etags (new
--etags option) and I want to match what the D lang spec would say is
private (if it did say).  For now I have to reverse engineer based on
compiler and forums, but don't want to mimic a compiler bug.


Is this expected? default to public members in private class

2015-05-03 Thread Dan Olson via Digitalmars-d-learn
It seems a private class or struct defaults to public members.  Just
curious if this is intended.  I would have expected private all the way
down unless overriden.

--- plugh.d
module plugh;
auto makeFoo() {return new Foo;}

private:

class Foo
{
void maybepriv() {}
private void priv() {}
public void pub() {}
}

--- xyzzy.d
module xyzzy;
import plugh;

void main()
{
auto f = makeFoo();
f.maybepriv();  // is accessible after all
//f.priv(); // err expected, member private
f.pub();
}

--
Dan Olson


Re: Is this expected? default to public members in private class

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 18:07:20 -0700, Dan Olson wrote:

 It seems a private class or struct defaults to public members.  Just
 curious if this is intended.  I would have expected private all the way
 down unless overriden.

i bet it is intended. protection of struct/class members is independed of 
protection of struct/class itself. this is good for code consistency: no 
changing of outer protection flags can alter struct/class inner 
machinery. so if you changed your mind about protection level of some 
global things, you shouldn't unnecessary fix your code in completely 
unrelated places.

signature.asc
Description: PGP signature