我有一個像這樣的結構。在find_if中使用謂詞
struct MaxWinPerElementInfo
{
std::string paytableName;
std::string elementName;
long long elementCredits;
bool multiplierRequired;
};
我想找到與paytableName
匹配的元素。爲此,我計劃使用帶謂詞功能的std::find_if
。
我宣佈struct MaxWinPerElementInfo
作爲內部函數對象,
bool operator() (const MaxWinPerElementInfo &elementInfo) const
{
return paytableName == elementInfo.paytableName;
}
現在,我試圖通過調用搜索元素,
std::find_if(elementInfo.begin(), elementInfo.end(), MaxWinPerElementInfo(paytable));
其中 elementInfo
是std::vector< struct MaxWinPerElementInfo >
和paytable
是std::string
。
爲此,我正在錯誤,no known conversion for argument 1 from ‘std::string {aka std::basic_string<char>}’ to ‘const MaxWinPerElementInfo&’
我不能使用C++ 11,因爲這是一個遺留代碼。
我在這裏失蹤了什麼?任何建議都會非常有幫助。
@Eric Fortin謝謝。我更新了我的帖子。 –