On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote:
Making a field static is effectively a global variable to the class.

I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, but this state actually needs to be different for each tree object. The reason for this is that structurally it will not change per tree and if it it is not static then it wastes space unnecessarily.


Is there any way to do this more naturally in D?

It seems to me like the obvious solution is to use two different classes, one to store the global state, and one to store the individual objects in your structure. For example:

class Tree {
    State state;
    Node root;

class Node {
    Node[] children;

Reply via email to