I have a vector vec that I need to sort every time I put an element inside it
so when I put the first Upgrade* inside the vector I have no problems
but when I put the second Upgrade* inside it and the sort routine is called I have a runtime error
this is how I put elements and call sort every time I insert
std::vector<Upgrade*> stack = getStack();
stack.push_back(element);
std::sort(stack.begin(), stack.end(), CostBenefitUpgradeOrder());
and this is my comparator
struct CostBenefitUpgradeOrder {
bool operator ()(const Upgrade * u1, const Upgrade * u2) const {
const UpgradeType upgradeType1 = u1->getUpgradeType();
const UpgradeType upgradeType2 = u2->getUpgradeType();
int price1 = PriceUtil::getPrice(upgradeType1);
int price2 = PriceUtil::getPrice(upgradeType2);
if (price2 < price1)
return true;
else
return false;
}
}
and this is the error

I have noticed that it only happens when I execute the program in Debug mode!!
, it is not the case that
,
, if
, if