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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -