Shouldn't the pointers be different
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 7 02:56:03 PST 2015
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
More information about the Digitalmars-d-learn
mailing list