pointer to iterator access method

I created a vector of an object. Then I had an iterator of the vector which lets me access each object in the vector. If I create a pointer iterator and set it to the address of one of these non-pointer iterators, how can I access a child of the object using the pointer?

Ex: I have this object:

1
2
3
4
5
6
7
struct obj
{
    int k;
    char t;
    
    obj* next;
};


std::vector<obj> ovec;

using a for-loop, I add say 2 instances of this object to a vector
1
2
3
4
for (int k..k < 2..)
{
    ovec.push_back(obj)
}


I get an iterator of ovec
std::vector<obj>::iterator oti = ovec.begin()

I get a pointer iterator
std::vector<obj>::iterator* pti = oti;

How do I access next using pti?

I mean if this oti->next = 0; works, why does this *pti->next = 0; not work?
Last edited on
You have to use parentheses (*pti)->next = 0;.
O my what a joke...lol thanks dude
What if I want to set pti to next

I tried this *pti = &(*pti)->next
Your terminology is not precise so I'm not sure exactly what you want to do. I suspect it's not possible.

I don't think I have seen anyone use pointers to iterators before. Are you sure you don't just overcomplicate things?
Last edited on
I am trying to implement dfs so I want to use iterator pointers intead of actual iterators. But this seems a bit complicated, so I will just use normal iterators
Topic archived. No new replies allowed.