--- In [email protected], Vic Wagner <[EMAIL PROTECTED]> wrote: > > saurabh jain wrote: > > Hi, > > I have something like this in my code: > > > > struct s{ > > ... > > ... > > struct s* next; > > > the "struct" is redundant (in C it was required, not C++). > > ... > > ... > > }; > > > > > > In a main I have: vector<s> vs; > > And I am using an iterator(vector<s>::iterator vsitr) to traverse the vector. What I want to know is how to assign the struct s* next of the structure using this iterator. > > > you're attempting to put a "link" in a struct which is held in a > vector? why??
Because I am traversing on a design(you can view it as a graph). So I need to have a link of previous nodes and the next nodes in some case. Out of all the nodes stored in a vector. > > I am doing something like : struct s* next = &(*vsitr); > > Is it correct? Seems to be working fine for me right now! Is there a cleaner , better and safer way to achieve this? > > > why not put an iterator in s instead of a pointer? Given the time and requirement of the job, that will be an over kill to modify the entire thing! > (there are some > things that C requires you to do that just get in the way in C++) I would love to do that, but best is not the feasible option always! :( > > Thanks, > > Saurabh > >
