0

我正在制作一个扑克评估器,对于直方图,我使用向量<对>来保存数据。现在我坚持对它们进行排序,无论我尝试什么都会得到编译器错误。

任何帮助表示赞赏,谢谢。

class Histogram {
private:
    vector< pair<int,int> > _rankHistogram;
    vector< pair<int,int> > _suitHistogram;

    void add(int rank, int suit) {
        for (int i=0; i < _rankHistogram.size(); i++)
            if (_rankHistogram[i].first == rank) { _rankHistogram[i].second++; break; }

        for (int i=0; i < _suitHistogram.size(); i++)
            if (_suitHistogram[i].first == suit) { _suitHistogram[i].second++; break; }
    }
    bool cmp_big_first (pair<int,int> i, pair<int,int> j) { return i.second < j.second; }

public:
    Histogram() {
        _rankHistogram.push_back( make_pair(TWO, 0) );
        _rankHistogram.push_back( make_pair(THREE, 0) );
        _rankHistogram.push_back( make_pair(FOUR, 0) );
        _rankHistogram.push_back( make_pair(FIVE, 0) );
        _rankHistogram.push_back( make_pair(SIX, 0) );
        _rankHistogram.push_back( make_pair(SEVEN, 0) );
        _rankHistogram.push_back( make_pair(EIGHT, 0) );
        _rankHistogram.push_back( make_pair(NINE, 0) );
        _rankHistogram.push_back( make_pair(TEN, 0) );
        _rankHistogram.push_back( make_pair(JACK, 0) );
        _rankHistogram.push_back( make_pair(QUEEN, 0) );
        _rankHistogram.push_back( make_pair(KING, 0) );
        _rankHistogram.push_back( make_pair(ACE, 0) );

        _suitHistogram.push_back( make_pair(SPADES, 0) );
        _suitHistogram.push_back( make_pair(HEARTS, 0) );
        _suitHistogram.push_back( make_pair(DIAMONDS, 0) );
        _suitHistogram.push_back( make_pair(CLUBS, 0) );
    }

    void operator() (Card &c) { add(c.getRank(), c.getSuit()); }

    void h_sort() {
        sort(_rankHistogram.begin(), _rankHistogram.end(), cmp_big_first);
    }

    void h_print() {
        for (int i=0; i<_rankHistogram.size(); i++) {
            cout << Card::rankToString(_rankHistogram[i].first) << "\t\t" << _rankHistogram[i].second << endl;
        }
    }
4

1 回答 1

4

你需要成功static cmp_big_first。如果不是静态的,该方法采用隐式this参数(类类型),这对您的使用没有意义。

于 2012-01-15T20:14:10.073 回答