将C++代码从 VS2003 迁移到 VS2010 后出现错误 C2678,错误 C2679:二进制'=':未找到采用类型为 'int' 的右侧操作数的运算符
Error C2678 after migrating C++ code from VS2003 to VS2010, error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int'
std::vector<std::string>::iterator it;
it = NULL;
do
{
if(it == NULL)
it = init.begin();
else
++it;
if(it == init.end())
return 1;
}
while(it->empty());
上面的代码在VS2003中工作得很好,但是当它迁移到VS2010时,它会给出编译错误,说
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1> c:program filesmicrosoft visual studio 10.0vcincludevector(388): could be 'std::_Vector_iterator<_Myvec> &std::_Vector_iterator<_Myvec>::operator =(const std::_Vector_iterator<_Myvec> &)'
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
1> while trying to match the argument list '(std::_Vector_iterator<_Myvec>, int)'
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
1>d:vs2010_wsacct ford 6.2.4 source codeacct_ford_wsvectorsrcdrivercancardxl.cpp(81): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion)
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
您假设vector迭代器可以从int类型(或某种形式的指针?)进行初始化和赋值。事实并非如此。
你可以把你的循环转换成:
if (init.empty())
return 1;
it = init.begin();
while (it->empty())
{
++it;
if (it == init.end())
return 1;
}
这是因为你试图将NULL赋值给迭代器(它不是指针!)编译器明确表示不支持此操作。顺便问一下,这样的任务是什么原因?
通常情况下,如果你想运行集合,你应该这样写:
for (VectorType::iterator it = init.begin(); it != init.end(); ++it)
{
// do something with it here
}
相关文章:
- 我的模板类方法返回错误类型?
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 类型为 "int*" 的参数与 C++ 中错误类型"int**"参数不兼容
- glDrawElements GL 错误类型 = 0x824c,严重性 = 0x9146,消息 = GL_INVALID
- Eclipse/CDT_C++给出"语义错误_"类型XXX无法解决"。项目运行
- turbo 为什么我的C++代码中出现错误类型名称预期"错误?
- "auto"推断出 hashtable_policy.h 中的错误类型
- 设计自己的结果/两者之一:是否应该始终指定成功类型和错误类型
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 在 vscode 上编译错误.类型说明符是 C++11 扩展
- 不允许使用错误类型
- 当读取错误类型时,CIN覆盖我的初始化值
- C++:"错误:类型'const char*'和'const char [28]'的操作数无效到二进制'ope
- 我的代码错误类型警告 1 警告 C4018 和更多错误
- 在shared_from_this()中的错误类型(在继承类中)(是否有dyn.type-ware shared Poi
- 为什么缩小转换范围不能防止错误类型的map.insert()失败
- 程序总是返回二进制'>>':找不到运算符,它采用错误类型的左操作数
- 错误:类型为 '.&' 来自类型的临时 '..*康斯特'
- 涉及将要馈送的向量转换为execvp的错误类型
- C++中是否存在错误类型