digitalmars.D.learn - Templates + protection attributes problem
- Kevin VR (33/33) Apr 06 2005 Hello,
- Joey Peters (10/43) Apr 07 2005 It only works for the same module when you also declare it private withi...
- Regan Heath (65/112) Apr 07 2005 Actually, no, both of those members above are accessable by another
- Regan Heath (4/117) Apr 07 2005 I forgot to say, post this to the digitalmars.D.bugs NG pls :)
Hello, I'm having a problem using templates and the protection attributes for class members. I can not access private declared methods from an other template class defined in the same module. For example when I put this in the same module: <code> public class Foo(T) { public this() { // Works ok. Bar!(T) bar = new Bar!(T)(); // Fails!? it's private, but in the same module!! bar.doSomething(); } } public class Bar(T) { public this() { } private void doSomething() { } } </code> The D-spec says the following: <quote> 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. </quote> I'm sure it has something to do with the templates, because the same thing without the templates works fine... Does anyone know how to solve this? thanks, Kevin
Apr 06 2005
It only works for the same module when you also declare it private within the module scope: private member; <- only for inside this module class Foo { private member; <- only for inside Foo {} } What you probably want is the package protection, use the package keyword: package void doSomething() {} "Kevin VR" <azra pandora.be> schreef in bericht news:d31ndi$amo$1 digitaldaemon.com...Hello, I'm having a problem using templates and the protection attributes for class members. I can not access private declared methods from an other template class defined in the same module. For example when I put this in the same module: <code> public class Foo(T) { public this() { // Works ok. Bar!(T) bar = new Bar!(T)(); // Fails!? it's private, but in the same module!! bar.doSomething(); } } public class Bar(T) { public this() { } private void doSomething() { } } </code> The D-spec says the following: <quote> 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. </quote> I'm sure it has something to do with the templates, because the same thing without the templates works fine... Does anyone know how to solve this? thanks, Kevin
Apr 07 2005
On Thu, 7 Apr 2005 13:02:33 +0200, Joey Peters <squirrel nidhogg.com> wrote:It only works for the same module when you also declare it private within the module scope: private member; <- only for inside this module class Foo { private member; <- only for inside Foo {} }Actually, no, both of those members above are accessable by another class/function etc in the same module. eg. import std.stdio; class A { private int aival; void foo(B b) { b.bival = 3; } } class B { private int bival; void foo(A a) { a.aival = 4; } } void main() { A a = new A(); B b = new B(); a.aival = 1; b.bival = 2; writefln(a.aival); writefln(b.bival); a.foo(b); b.foo(a); writefln(b.bival); writefln(a.aival); }"Kevin VR" <azra pandora.be> schreef in bericht news:d31ndi$amo$1 digitaldaemon.com...Nope. It looks like a bug to me, here is another case demonstrating one that works, and one that doesn't. class Bar(Type) { this() { } private void doSomething() { } } class Baz { this() { } private void doSomething() { } } void main() { //this is ok Baz a = new Baz(); a.doSomething(); //this fails Bar!(int) b = new Bar!(int)(); b.doSomething(); } ReganHello, I'm having a problem using templates and the protection attributes for class members. I can not access private declared methods from an other template class defined in the same module. For example when I put this in the same module: <code> public class Foo(T) { public this() { // Works ok. Bar!(T) bar = new Bar!(T)(); // Fails!? it's private, but in the same module!! bar.doSomething(); } } public class Bar(T) { public this() { } private void doSomething() { } } </code> The D-spec says the following: <quote> 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. </quote> I'm sure it has something to do with the templates, because the same thing without the templates works fine... Does anyone know how to solve this?
Apr 07 2005
On Fri, 08 Apr 2005 00:27:37 +1200, Regan Heath <regan netwin.co.nz> wrote:On Thu, 7 Apr 2005 13:02:33 +0200, Joey Peters <squirrel nidhogg.com> wrote:I forgot to say, post this to the digitalmars.D.bugs NG pls :) You can post my example or yours or both, up to you. ReganIt only works for the same module when you also declare it private within the module scope: private member; <- only for inside this module class Foo { private member; <- only for inside Foo {} }Actually, no, both of those members above are accessable by another class/function etc in the same module. eg. import std.stdio; class A { private int aival; void foo(B b) { b.bival = 3; } } class B { private int bival; void foo(A a) { a.aival = 4; } } void main() { A a = new A(); B b = new B(); a.aival = 1; b.bival = 2; writefln(a.aival); writefln(b.bival); a.foo(b); b.foo(a); writefln(b.bival); writefln(a.aival); }"Kevin VR" <azra pandora.be> schreef in bericht news:d31ndi$amo$1 digitaldaemon.com...Nope. It looks like a bug to me, here is another case demonstrating one that works, and one that doesn't. class Bar(Type) { this() { } private void doSomething() { } } class Baz { this() { } private void doSomething() { } } void main() { //this is ok Baz a = new Baz(); a.doSomething(); //this fails Bar!(int) b = new Bar!(int)(); b.doSomething(); }Hello, I'm having a problem using templates and the protection attributes for class members. I can not access private declared methods from an other template class defined in the same module. For example when I put this in the same module: <code> public class Foo(T) { public this() { // Works ok. Bar!(T) bar = new Bar!(T)(); // Fails!? it's private, but in the same module!! bar.doSomething(); } } public class Bar(T) { public this() { } private void doSomething() { } } </code> The D-spec says the following: <quote> 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. </quote> I'm sure it has something to do with the templates, because the same thing without the templates works fine... Does anyone know how to solve this?
Apr 07 2005