How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

curiousprogramma08 _ at gmail.com
Fri Mar 29 22:50:53 UTC 2024


```d
struct QueueNode
{

     private int data;
     private QueueNode *next = null;

     this(int data)
     {
         this.data = data;
     }
}
```
I also tried to write it like this too:

```d
struct QueueNode
{

     private:
     int data;
     QueueNode *next = null;

     public:
     this(int data)
     {
         this.data = data;
     }
}
```
(I will use readonly ```@property``` as only way to read them)

But ```data``` and ```next``` can be changed and can be read from 
outside of the structure. What to do to prevent fields from being 
read and changed from outside the structure?



More information about the Digitalmars-d-learn mailing list