作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 enum
,一个以这个 enum
作为成员的结构和这些结构的 vector :
enum TickerType { tt1, tt2, tt3 };
struct Ticker {
std::string name;
TickerType type;
};
std::vector<Ticker> vect;
我想在 vect
中搜索类型为 tt1
的元素。为此我声明
struct find_ticker
{
const TickerType type;
find_ticker(TickerType type) : type(type) {};
bool operator () ( const Ticker& ticker ) const
{
return ticker.type == type;
}
};
并查看:
if ( std::find ( vect.begin(), vect.end(), find_ticker ( tt1 ) ) != tickers.end() )
但是我明白了
error: no match for ‘operator==’ (operand types are ‘Dfp::Ticker’ and
‘const {anonymous}::find_ticker’) || { return *__it == _M_value; }
*Dfp是应用的全局命名空间,find_ticker定义在我需要的实现文件中的匿名命名空间
最佳答案
std::find
如果您想使用谓词进行查找,函数是错误的调用函数。 std::find
用于根据值查找,因此您要尝试在 vector 中查找等于 find_ticker
对象的值。
你应该使用 std::find_if
相反。
关于c++ - 在 C++ 中的 vector 中的结构中搜索枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39614118/
我是一名优秀的程序员,十分优秀!