1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
std::set<AbstractComponent<T>*, AbstractComponentCmp<T> > touches = (ptr_sconn)->addPointCheckTouchs(vox);
{
ptr_sconn->merge(*it_touches, vox);
//sconn is my set of pointers to Component<T,OP>, with customized comparator ComponentCmp<T,OP>.
//Here I determine [my_ptr], which is is the element I want to erase
Component<T,OP>* my_ptr = static_cast<Component<T,OP>*>(*it_touches);
//Here I search for my_ptr in the set. if not found, I print out a message
//whrn I compile and run, I get the message
typename std::set<Component<T,OP>*, ComponentCmp<T,OP> >::iterator my_ite = sconn.find(my_ptr);
if (my_ite == sconn.end()) printf("element not found!!!\n");
//Here I loop through the entire set, and the element IS FOUND
for (typename std::set<Component<T,OP>*, ComponentCmp<T,OP> >::iterator it = sconn.begin(); it!=sconn.end(); ++it)
{
ComponentCmp<T,OP> comparator; //comparator is the operator that is used to determine if two elements in the set are the same
bool b1 = !comparator(*it, my_ptr);
bool b2 = !comparator(my_ptr, *it);
printf("*it = %p, my_ptr = %p, b = %d\n\n", *it, my_ptr, b1&&b2);
if(b1 && b2) printf("CONTRADDICTION!! element found!!!\n");
Component<T,OP> my_cmp = **it;
}
//here I try to erase the element by passing the iterator.
//HERE IT CRASHES
sconn.erase(my_ite);
//ALTERNATIVE: here I try to erase the element by passing the element directly instead of the iterator
//IT DOES NOT CRASH. HOWEVER, THE SIZE OF THE SET IS REDUCED BY TWO, WHICH MAKES NO SENSE!!!
//sconn.erase(my_ptr);
//printf("erased\n");
//printf("sconn.size = %d, distance = %d\n", sconn.size(), std::distance(sconn.begin(), sconn.end()));
//delete my_ptr;
}
|