pointers - List of nodes pointing to parent C++ -


i storing custom data structures in list, each 1 points it's parent.

here data structure

struct block{     int someval;     block * parent = 0; } 

i need fill list 'block's , each 1 needs point parent, initialise follows:

block q; std::vector<block> something;   // assume filled 4 blocks 

i init first object in list have parent point (easy way identify last element)

something[0].parent = &something[0]; 

as setting others, logic:

for(int = 1; < 3; i++){     something[i].parent = &q;     q = something[i]; }  

now, looks should produce like:

something[0].parent = #address of something[1].parent = #address of 0 something[2].parent = #address of 1 something[3].parent = #address of 2 

but it's assiging memory location of something[0]

any ideas why happening?


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -