所以我想排序向量中存储的卡片矢量。C++ STL排序向量
载体是std::vector<CUE>
CUE是一个类,它代表“卡下评估”,而里面的卡是const Card*
。我需要的是使用我创建的名为compareCards
的函数对卡片进行排序。
不过,我产生了以下错误:
error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'CUE'
函数声明是在叫Table.h
另一个文件,以及排序通话中Table.cpp
。这整个事情都是为了我正在创造的一场扑克比赛,但是整理手牌产生了一个让我停下来的错误。
如何在成功分选手的同时摆脱此错误?
下面是相关代码:
排序召唤:
Table.cpp
std::sort(cardvec.begin(), cardvec.end(), compareCards);
函数声明:
Table.h
bool compareCards(const Card* c1, const Card* c2)
{
return c1->GetPip() < c2->GetPip();
}
CUE。 h
#pragma once
#include <vector>
#include <iostream>
#include "card.h"
struct CUE
{
CUE(void);
~CUE(void);
CUE(const std::vector<const Card*>& c) : _cue(c){}
std::vector<const Card*> _cue;
};
在C++中,你不需要添加空隙参数的功能。 – RedX
什么是Pip?它是否可排序? – RedX
我认为你的回调函数'compareCards'有错误的原型 – Bathsheba