Dlang and POO
christophe__c
carpentier-christophe at hotmail.fr
Mon Jun 21 10:01:03 UTC 2021
Hello to all,
I'm starting to program in Dlang. I use for the moment the online
editor.
I test the following code:
```D
import std;
class User
{
private string name;
private:
string firstname;
int age;
public:
override string toString()
{
return (format("User: %s %s - (%s)", this.name,
this.firstname, this.age));
}
};
void main()
{
auto bob = new User();
bob.name = "Bob";
bob.firstname = "McDean";
bob.age = 15;
writeln(bob);
}
```
and I don't understand why I can modify private members from
outside my class.
I had understood that it was required to create accessors to have
this behavior.
Thanks in advance to all for your welcome and your answers.
Christophe__c
More information about the Digitalmars-d
mailing list