Sort and Sum

Hi.! can anyone tell me what is wrong with this function.?

double sort_sum(std::vector<double>& vec)
{
std::multiset<double> mset(vec.begin(), vec.end());
while (mset.size() > 1) {
std::multiset<double>::const_iterator itA = mset.begin();
std::multiset<double>::const_iterator itB = ++mset.begin();
double sum = *itA + *itB;
mset.erase(itA, itB);
mset.insert(c);
}
return !mset.empty() ? *mset.begin() : 0.0;
}

I want to determine the sum of all elements of vector vec and return it. I have to do it exactly this way, by using sets...However this is an infinite loop.
http://www.cplusplus.com/reference/set/multiset/erase/
the range is [), so in every iteration you erase one element and insert one element.
Topic archived. No new replies allowed.