When we iterate through the set, can we somehow change the value of the object in the set? So I have a class Student which have a name and a num.
Add all these student in the set. When I iterate through the set, how can I change the value of "num"? In another word, I want to do something like this
Interator it->num = 10; //Sucks!!! this does not work :( :(
I know change the value of "num" is a bad idea, because the set will not reorder by itself, but I just want to know and plus what if I want to change Tom and Arab instead of num. Please help
I think it is the problem with set. It seems to me that set::iterator return a const void * instead of void*, so when I try to do memcpy, it complain that "invalid conversion from const void * to void*". It sucks!!! I guess I will just changed my container to list to make my life easier.
The reason I didnt use list in the beginning is because, I have to keep elements in my container in order. Since set always keep all it element in order and simply insert new element into the right place, so it is O(n) instead of sorting the elements every time like list O(nlog(n)). But oh well
set's iterator is a typedef of its const_iterator because allowing the user to change the value of an
element through an iterator could potentially break set's guarantee of uniqueness of all elements.