【发布时间】:2016-09-23 06:27:19
【问题描述】:
所以我无法使用 find 函数在我的结构向量中查找具有与指定的相同 'char' 值的节点。这是我的结构代码,我正在重载比较运算符,但仍然没有任何运气
// STRUCT
struct alpha
{
string morse;
char letter;
// overload the comparison operator
bool operator==(const alpha& a) const
{
return letter == a.letter;
}
};
这是我的迭代器的代码
void testFunc(vector<alpha> &vect)
{
std::vector<alpha>::iterator it;
it = find(vect.begin(), vect.end(),'e');
if(it != vect.end())
{
// do anything if we ever get here
}
}
任何帮助将不胜感激,我的代码甚至无法编译我得到错误
Invalid operands to binary expression ('alpha' and 'int')
【问题讨论】:
-
bool operator==(const code& a) constcode是什么? -
code这个类型是在哪里定义的? -
更好的数据结构可以是
std::map<char,std::string>或哈希映射。
标签: c++ algorithm vector struct iterator