C++ 错误C2678:二进制'=';:找不到操作员

C++ 错误C2678:二进制'=';:找不到操作员,c++,visual-c++,operator-overloading,C++,Visual C++,Operator Overloading,完整的错误消息: Error 1 error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'const std::_List_iterator<_Mylist>' (or there is no acceptable conversion) c:\ebooks\sourcecode\programing_game_ai_by_example\buckland

完整的错误消息:

Error   1   error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'const std::_List_iterator<_Mylist>' (or there is no acceptable conversion)    c:\ebooks\sourcecode\programing_game_ai_by_example\buckland_sourcecode\vs8 projects\buckland_chapter3-steering behaviors\path.h 54  1   Steering
问题变量的声明:

std::list<Vector2D>::iterator  curWaypoint;
现在我不确定在这之后要去哪里,但是列表和迭代器定义在文件中

我不会粘贴相同的剩余错误,但是您可以访问整个Path.h文件

有人能告诉我怎么解决这个问题吗?我一直害怕C++,特别是VC++,但是如果有人告诉我这个问题是什么,我可以自己解决它,并修复它。 错误

Error   1   error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'const std::_List_iterator<_Mylist>' (or there is no acceptable conversion)    c:\ebooks\sourcecode\programing_game_ai_by_example\buckland_sourcecode\vs8 projects\buckland_chapter3-steering behaviors\path.h 54  1   Steering
Error   2   error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'const std::_List_iterator<_Mylist>' (or there is no acceptable conversion)    c:\ebooks\sourcecode\programing_game_ai_by_example\buckland_sourcecode\vs8 projects\buckland_chapter3-steering behaviors\path.h 54  1   Steering
Error   3   error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'const std::_List_iterator<_Mylist>' (or there is no acceptable conversion)    c:\ebooks\sourcecode\programing_game_ai_by_example\buckland_sourcecode\vs8 projects\buckland_chapter3-steering behaviors\path.h 54  1   Steering
Error   4   error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'const std::_List_iterator<_Mylist>' (or there is no acceptable conversion)    c:\ebooks\sourcecode\programing_game_ai_by_example\buckland_sourcecode\vs8 projects\buckland_chapter3-steering behaviors\path.h 54  1   Steering
    5   IntelliSense: no operator "!=" matches these operands
            operand types are: const std::_List_iterator<std::_List_val<std::_List_simple_types<Vector2D>>> != int  c:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter3-Steering Behaviors\Path.h 54  38  Steering

不能将迭代器与NULL进行比较,这就是为什么会出现这些错误。据我所知,除非您将其设置为某个值,否则无法检查和迭代器是否指向某个值。将其设置为
end()
将使其成为一种空迭代器(因为end()是容器中最后一个元素之后的元素,所以它基本上不指向任何内容)。

迭代器与
空迭代器进行比较是无效的:

assert(curWaypoint != NULL);
我没有看过您的所有代码,但您可能想将其与
end()
进行比较:


您可以在构造函数中初始化
curWaypoint
,这样就可以按您的意愿工作。

我的原始源代码副本与您的有点不同

  //returns the current waypoint
  Vector2D    CurrentWaypoint()const{assert(*curWaypoint != NULL); return *curWaypoint;}

TBL:在我的代码副本中,它不是在测试迭代器,而是在测试迭代器所指向的内容。不幸的是,我得到了与您相同的错误。

设置它做
end
什么?(否则,事实上,似乎无法确定迭代器是否有效)如@JaredC所说,我看不到您的所有代码,但如果您的类中有任何容器,请在构造函数中将迭代器设置为其结尾。当我更改比较时,它给出了错误C2039:“end”:不是“std::\u List\u迭代器”的成员。是否确实是
m\u航路点。end()
?因为如果是这样的话,那个错误就没有意义了。我首先写了错误的代码(错误的变量)。谢谢我想知道原始源代码是如何对作者起作用的?我也遇到了这个问题。你从哪里得到来源的副本的?我从我的房间里拿的。我的与问题中的相同(即,不带“*”)。
Conversion Report - WestWorld1.vcproj: 
Converting project file 'C:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter2-State Machines\WestWorld1\WestWorld1.vcproj'. 
Web deployment to the local IIS server is no longer supported. The Web Deployment build tool has been removed from your project settings. 
Done converting to new project file 'C:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter2-State Machines\WestWorld1\WestWorld1.vcxproj'. 
This application has been updated to include settings related to the User Account Control (UAC) feature of Windows Vista. By default, when run on Windows Vista with UAC enabled, this application is marked to run with the same privileges as the process that launched it. This marking also disables the application from running with virtualization. You can change UAC related settings from the Property Pages of the project. 
VCWebServiceProxyGeneratorTool is no longer supported. The tool has been removed from your project settings. 
MSB8012: $(TargetPath) ('C:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter2-State Machines\WestWorld1\.\Debug\WestWorld1.exe') does not match the Linker's OutputFile property value '.\Debug/WestWorld1.exe' ('C:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter2-State Machines\WestWorld1\Debug/WestWorld1.exe') in project configuration 'Debug|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetPath) property value matches the value specified in %(Link.OutputFile). 
MSB8012: $(TargetPath) ('C:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter2-State Machines\WestWorld1\.\Release\WestWorld1.exe') does not match the Linker's OutputFile property value '.\Release/WestWorld1.exe' ('C:\eBooks\SourceCode\programing_game_ai_by_example\Buckland_SourceCode\VS8 projects\Buckland_Chapter2-State Machines\WestWorld1\Release/WestWorld1.exe') in project configuration 'Release|Win32'. This may cause your project to build incorrectly. To correct this, please make sure that $(TargetPath) property value matches the value specified in %(Link.OutputFile). 
assert(curWaypoint != NULL);
assert(curWaypoint != m_WayPoints.end());
  //returns the current waypoint
  Vector2D    CurrentWaypoint()const{assert(*curWaypoint != NULL); return *curWaypoint;}