Question about property & method access scope.

cc cc at nevernet.com
Tue May 11 10:47:15 UTC 2021


On Tuesday, 11 May 2021 at 09:10:02 UTC, Vinod K Chandran wrote:
> Hi all,
> I am practising D with a win api GUI hobby project.
> I have a Window class and it resides in module window.d
> My WndProc function resides in another module named 
> wnd_proc_module.d
> Inside my WndProc, I get the Window class like this.
> ```d
> Window win = cast(Window) (cast(void*) GetWindowLongPtrW(hWnd, 
> GWLP_USERDATA)) ;
> ```
> So in many situations, I need to check some boolean properties 
> of Window class and call some functions of Window class in 
> WndProc.
> But I don't want to expose those props and functions to the 
> user. So if I make them private, I can't access them inside the 
> WndProc function. How do solve this issue. Thanks in advance.

The `package` protection attribute should work here if the 
modules reside in the same package (directory)?

```d
module mywindow.window;
import mywindow.wnd_proc_module.d
class Window {
     package int x, y;
}
```

```d
module mywindow.wnd_proc_module.d
import mywindow.window;
class Proc {
     Window win;
     void doStuff() {
         win.x = 3;
     }
}
```


More information about the Digitalmars-d-learn mailing list