digitalmars.D.bugs - Private classes not really private?
- Jarrett Billingsley (23/23) Jan 09 2005 charset="iso-8859-1"
- John Reimer (13/40) Jan 09 2005 I'm not sure what the exact answer to this question is, but you will
- Jarrett Billingsley (2/12) Jan 10 2005 Perhaps. However, wouldn't it make more sense (and be more useful) if w...
- Regan Heath (16/28) Jan 11 2005 Try this:
charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable According to the D spec: "Private means that only members of the enclosing class can access the = member, or members and functions in the same module as the enclosing = class." However: [mod.d] -------------- module mod; private int x; private class A {} [main.d] -------------- import mod; void main() { writefln(x); // Illegal, as it should be A a=3Dnew A; // Shouldn't this be illegal? } Private variables in modules are inaccessible, but private classes are = public..?
Jan 09 2005
Jarrett Billingsley wrote:According to the D spec: "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class." However: [mod.d] -------------- module mod; private int x; private class A {} [main.d] -------------- import mod; void main() { writefln(x); // Illegal, as it should be A a=new A; // Shouldn't this be illegal? } Private variables in modules are inaccessible, but private classes are public..?I'm not sure what the exact answer to this question is, but you will notice that there is a difference between "private int x;" which "instantiates" an actual variable and "private class A" which merely declares the details of a class; the instantiation of the class does not occur until the main function. Therefore, there's a distinct difference between the two declarations. With that understanding, I don't think that the "private" in the class A declaration should be expected to do the same thing. In fact, I'm not sure if the "private" keyword does anything in this instance. Perhaps the "package" attribute is useful in this circumstance. Later, John R.
Jan 09 2005
I'm not sure what the exact answer to this question is, but you will notice that there is a difference between "private int x;" which "instantiates" an actual variable and "private class A" which merely declares the details of a class; the instantiation of the class does not occur until the main function. Therefore, there's a distinct difference between the two declarations. With that understanding, I don't think that the "private" in the class A declaration should be expected to do the same thing. In fact, I'm not sure if the "private" keyword does anything in this instance. Perhaps the "package" attribute is useful in this circumstance.Perhaps. However, wouldn't it make more sense (and be more useful) if we could make classes private to the module?
Jan 10 2005
On Mon, 10 Jan 2005 18:54:07 -0500, Jarrett Billingsley <kb3ctd2 yahoo.com> wrote:Try this: --[mod.d]-- module mod; class A { private this() { } } --[main.d]-- import mod; void main() { A a = new A(); } ReganI'm not sure what the exact answer to this question is, but you will notice that there is a difference between "private int x;" which "instantiates" an actual variable and "private class A" which merely declares the details of a class; the instantiation of the class does not occur until the main function. Therefore, there's a distinct difference between the two declarations. With that understanding, I don't think that the "private" in the class A declaration should be expected to do the same thing. In fact, I'm not sure if the "private" keyword does anything in this instance. Perhaps the "package" attribute is useful in this circumstance.Perhaps. However, wouldn't it make more sense (and be more useful) if we could make classes private to the module?
Jan 11 2005