Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

[RESOLVED] Program crashing

$
0
0
Hi, ALL,
Since I don't know how to remove SOLVED from the thread and this is actually kind of different issue I decided to make a new thread.

This is a continuation of this thread.

Thank you Paul for the code. It did compile and ran fine.
However when I tried to erase and then insert the element into std::set program crashed.

Here is the code:

Code:

for( MapStringToPair::iterator it = m_score.begin(); it != m_score.end(); it++ )
{
        std::string score = (*it).first;
        bool found = false;
        double value;
        for( SDSetPair::iterator it1 = (*it).second.begin(); it1 != (*it).second.end() && !found; it1++ )
        {
                if( (*it1).first == owner )
                {
                        value = (*it1).second;
                        found = true;
                }
                (*it).second.erase( SDPair( owner, value ) );
                (*it).second.insert( std::make_pair( owner, value + player.GetAmountPaid() ) );
        }
}

The program is crashing on "(*it).second.insert()" call with the message "invalid operator<".

I also had to modify the operator() this way:

Code:

bool operator()(const SDPair &lhs, const SDPair &rhs) const
{
        if( lhs.second < rhs.second )
                return true;
        else
                return lhs.first < rhs.first;
}

Anybody have an idea?

Thank you.

Viewing all articles
Browse latest Browse all 3021