Nick:

The two nodes have the same address, is this right?

What you are printing is the address of the reference in the stack frame of add(). If you want to print the reference you can use this:


import std.stdio;

class Test(T) {
    static class Node {
        T v;
    }

    void add(T e) {
        auto n = new Node;
        writeln("New node address: ", cast(void*)n);
    }
}

void main() {
    auto t = new Test!int;

    t.add(0);
    t.add(1);
}


Note also that class/struct/enum/union names in D start with an upper case. I have also used a static class instead.

Bye,
bearophile

Reply via email to