Closed shokrof closed 2 years ago
Hi,
that could be done of course but: why not keeping a pointer to an object of type sshash::dictionary
and then using the pointer to get the iterator, e.g., auto it = obj->begin()
?
Hi, I think it won't work because I want to keep the iterator data during the lifetime of my class. It is not recommended to make a pointer point to a memory on the stack(created by obj->begin()).
I fixed for myself. I used pointer and created its value using "new iterator(dictionary pointer)". then I used it with dictionary::begin() and dictionary::at()
Thanks
The pointer obj
in my previous answer is a pointer to a dictionary object,
not a pointer to an iterator. The dictionary's memory is not allocated on the stack.
So your class can either include an object sshash::dictionary
as a private member
of have a pointer to it if you do not want to explicitly manage its memory.
If you keep an iterator as member of your class, then how would you initialize it?
You will need to do something like: it = iterator(dictionary const* ptr)
.
So you need a pointer to a dictionary object and the best thing to do is to keep it
as I mentioned before. Hope it is clear now. If not, let me know -- I'm glad to help.
yeah, I got thank you
Hey, I am using sshash as submodule in my project. It will make my life much easier if you added an empty constructor for dictionary::iterator. I am getting this error "error: no matching function for call to ‘sshash::dictionary::iterator::iterator()’". I am not using the constructor directly but I am keeping an iterator as a member in my classes.
Thanks, Moustafa