Quantcast
Channel: MarsHut
Viewing all articles
Browse latest Browse all 6551

Get object address when creating it in for loop

$
0
0
How to get and address of newly created object and put it in
pointer array?

int maxNeurons = 100;
Neuron*[] neurons = new Neuron*[](maxNeurons);

Neuron n;

for(int i = 0; i < maxNeurons; i++)

n = new Neuron();
neurons[] = &n; // here &n always returns same adress

writefln("Thread func complete. Len: %s", neurons);

This script above will print array with all the same address
values, why is that?

Thanks

Viewing all articles
Browse latest Browse all 6551

Latest Images

Trending Articles



Latest Images