c++ - std::sort comparing elements to null -


Text after "

I sort the following sorting algorithm, which sorts a std :: vector unique to Armor_set Some properties of my sorting algorithm by pointers, it is chokes and undefined behavior which is a valid LHS for RHS which is a nullptr The comparison runs in the ends>.

Despite the algorithm running several times, I am unable to understand the problem. I feel as if I'm missing out on some simple rules, how should I comply with the work of this std :: sort algorithm?

Any help would be appreciated.

  std :: vector & lt; Armor_set * & gt; Armor_sets; // Here the unique armor set entry std :: type (armor_sets.begin (), armor_sets.end (), [] (armor_set * LHS, armor_set * RHS) {automatic lhs_collectible_count = collectible_mgr :: mill () count. (LHS -> required_collectible); auto rhs_collectible_count = collectible_mgr :: mill () count (rhs-> needed_collectible); if (lhs_collectible_count> 0 & amp; amp; amp; rhs_collectible_count == 0) {return true;} If any other (lhs_collectible_count = = rhs_collectible_count) {LHS-> return> sort_index> gt; rhythoday; Gt; collectibles_needed; return lhs_collectibles_needed_count & gt; Rhs_collectibles_needed_count;}});  

Comparison function should strictly follow the weak-order

< P> For example, if I am a sort function, then I give you two armored indicators, "Who comes first?" And you consider a true / false value that comes first. I then give you the same two Armor_set points, but this time, changing the order of the item, I ask you the same question "Which comes first?" Then you return the same right / wrong value. What do you think - you lose

In short, this is a violation of the stringent weak order. There is no way a & lt; B , and at the same time b < A . Looking at some of your complex comparison function, I guess you are violating this rule

If you are using Visual Studio, then debug runtime is accurate for ordering violation in this way. Checks the comparison function is called twice, with A, B order for the first time and B, with A order for the second time. Return value is compared to each call, and if there is a violation then there will be an emphasis.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -