gpt4 book ai didi

c++ - 错误 C2678 : binary '!=' : no operator found

转载 作者:行者123 更新时间:2023-11-30 02:57:43 27 4
gpt4 key购买 nike

完整的错误信息:

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

我是 [V]C++ 世界的新手。我正在阅读 Programing Game AI by Example 书并尝试研究/分析 source code可以在发布者网站上找到。

似乎整个源代码都是用 VS8 编写的,但我使用的是 VS12 Express 版本。项目转换似乎没有问题,我收到了所有项目的 4 条警告(见下文)。

但问题是我遇到了一个编译错误,在我看来,我的基本知识是强类型列表的运算符重载,但我不确定它是否属实,我如果它是真的,不知道如何修复它。

错误#1 的代码行:

Vector2D    CurrentWaypoint()const{assert(curWaypoint != NULL); return *curWaypoint;}

问题变量声明:

std::list<Vector2D>::iterator  curWaypoint;

包含构造函数的扩展代码片段:

//constructor for creating a path with initial random waypoints. MinX/Y
//& MaxX/Y define the bounding box of the path.
Path(int NumWaypoints,
double MinX,
double MinY,
double MaxX,
double MaxY,
bool looped):m_bLooped(looped)
{
CreateRandomPath(NumWaypoints, MinX, MinY, MaxX, MaxY);

curWaypoint = m_WayPoints.begin();
}


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

//returns true if the end of the list has been reached
bool Finished(){return !(curWaypoint != m_WayPoints.end());}

现在我不确定在这之后去哪里,但是列表和迭代器定义在 WindowsUtils.h 中文件。

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

谁能告诉我如何解决这个问题?我总是害怕 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

以防万一,如果这很重要,下面是我在本书源代码中为每个项目不断收到的警告

*常见的解决方案转换警告:*(注意:和上面不是同一个项目)

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).

最佳答案

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

关于c++ - 错误 C2678 : binary '!=' : no operator found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14294116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com