I use the built-in qsort() function to sort the class item pointer vector.
class item { int value; vector<char> c; ... ... }; //Declaration of vector vector<item*> items; //Function Call qsort(&items, items.size(), sizeof(item*), value_sort); int value_sort(const void* a, const void* b) { item* pa = *(item**) a; item* pb = *(item**) b; if (pb->value < pa->value) return 1; else if (pa->value < pb->value) return -1; return 0; }
In debug mode, neither pa nor pb points to a valid location. The set of all class items , indicated by pa or pb , contains garbage values. Where am I mistaken? I'm also not sure about using double pointers.
Thanks.
source share