【发布时间】:2012-02-29 12:20:21
【问题描述】:
我正在编写一个回调函数,它引用了一个在结构中传递给它的 int 向量。当我尝试使用下标运算符 [] 访问向量中的元素时,Intellisense 指示 == 无法比较这两个元素,具体错误是 错误 C2678:二进制“==”:未找到采用“std::vector<_ty>”类型的左侧操作数的运算符(或没有可接受的转换)。但是使用 at() 函数时没有问题。
//body of call back function
searchInfo* argVal = (searchInfo*) Parameter;
for(int i = argVal->inclStartPos; i < argVal->exclEndPos; ++i){
if(argVal->numVector[i] == argVal->searchNum)//problem here
argVal->result = true;
//this is the structure passed through pointer
struct searchInfo{
int inclStartPos;
int exclEndPos;
vector<int>* numVector;
int searchNum;
bool result;
};
由于向量的 [] 运算符和 at() 函数几乎以相同的方式工作(这里的区别无关紧要),为什么会出错?
【问题讨论】:
标签: c++ windows api stl vector