Shouldn't the pointers be different

Nick via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 7 06:19:52 PST 2015


On Wednesday, 7 January 2015 at 10:56:07 UTC, bearophile wrote:
> 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

It works!
And thanks for the comments on the code :)


More information about the Digitalmars-d-learn mailing list