www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - private in class - or is it?

reply "dominik" <aha aha.com> writes:
ok, I'm really having problems with understanding this.. private should be 
private, no? I didn't find anything related to this in documentation. 
Apparently, private has no meaning - not the way as I see it anyways. Works 
both with private keyword preceding variable or private block {}

I'm using 2.005 - but works the same way in 1.x

code:
-----------------------------------
import std.stdio;

class Testor {

 private int m_something;

 this() {
  m_something = 5;
  writefln(m_something);
 }

 ~this() {
  writefln("Bye now...");
 }

 void give_me() {
  writefln(m_something);
 }
 void set_me(int x) {
  m_something = x;
 }
}

void main(char[][] args) {

 Testor blabla = new Testor; // writefln from this() == 5

 blabla.give_me(); // Works as it should == 5
 blabla.m_something = 88; // WTF??
 blabla.give_me(); // == 88

 blabla.set_me(983); // Works as it should == 983
 blabla.give_me(); // == 983


 delete blabla;
}
----------------------------------- 
Oct 06 2007
next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
dominik wrote:
 ok, I'm really having problems with understanding this.. private should be 
 private, no? I didn't find anything related to this in documentation. 
 Apparently, private has no meaning - not the way as I see it anyways. Works 
 both with private keyword preceding variable or private block {}
 
 I'm using 2.005 - but works the same way in 1.x
http://www.digitalmars.com/d/attribute.html "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***." I think we need to make that part bold, bright red and flashing... -- Daniel :P
Oct 06 2007
next sibling parent BCS <ao pathlink.com> writes:
Reply to Daniel,

 dominik wrote:
 
 ok, I'm really having problems with understanding this.. private
 should be private, no? I didn't find anything related to this in
 documentation. Apparently, private has no meaning - not the way as I
 see it anyways. Works both with private keyword preceding variable or
 private block {}
 
 I'm using 2.005 - but works the same way in 1.x
 
http://www.digitalmars.com/d/attribute.html "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***." I think we need to make that part bold, bright red and flashing...
and 64pt font.
 
 -- Daniel
 
 :P
 
Oct 06 2007
prev sibling parent "dominik" <aha aha.com> writes:
"Daniel Keep" <daniel.keep.lists gmail.com> wrote in message 
news:fe8d2c$ul3$1 digitalmars.com...
 I think we need to make that part bold, bright red and flashing...

 -- Daniel

 :P
make it so man, make it so :)
Oct 06 2007
prev sibling parent reply Frank Benoit <keinfarbton googlemail.com> writes:
http://www.digitalmars.com/d/attribute.html#ProtectionAttribute

cite:
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.
Oct 06 2007
parent reply "dominik" <aha aha.com> writes:
"Frank Benoit" <keinfarbton googlemail.com> wrote in message 
news:fe8dbi$uqf$1 digitalmars.com...
 http://www.digitalmars.com/d/attribute.html#ProtectionAttribute

 cite:
 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.
I guess that's made for modularization - easing in between classes in same module, makes sense now. I don't have enough experience to tell if that is good or bad though. Thank you.
Oct 06 2007
parent Frank Benoit <keinfarbton googlemail.com> writes:
 I guess that's made for modularization - easing in between classes in same 
 module, makes sense now. I don't have enough experience to tell if that is 
 good or bad though. Thank you. 
From the thread "Class declaration" Bill said: D doesn't have C++'s "friend" so that's sort of D's substitute.
Oct 06 2007