2013-01-12 107 views
1

完整的錯誤消息:錯誤C2678:二進制 '=!':沒有操作員發現

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++的世界。我正在閱讀編程遊戲AI示例書,並試圖研究/分析出版商網站上提供的source code

似乎整個源代碼都是用VS8編寫的,但我使用的是VS12 Express版本。項目轉換似乎沒有問題,期望我得到所有項目的4個警告(見下文)。

但問題是,我得到這在我看來,基本的知識我是運算符重載一個強類型列表編譯錯誤,但我不知道是否是真的,我不知道如何如果它是真的的話就修復它。錯誤#1

代碼行:

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

擴展的代碼片段,包括構造函數:

Vector2D CurrentWaypoint()const{assert(curWaypoint != NULL); return *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());} 

現在,我不知道在哪裏去之後,但列表和迭代器定義在內文件。

我不是粘貼剩餘誤差,這是一樣的,但是你可以訪問整個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). 

回答

0

比較的iteratorNULL是無效的:

assert(curWaypoint != NULL); 

我沒有看所有的代碼,但也許你的意思是這個比較end()

assert(curWaypoint != m_WayPoints.end()); 

你初始化curWaypoint在你的構造函數中,所以這應該按照你的意圖工作。

+0

當我改變比較,它給了錯誤C2039:'結束':不是'std :: _ List_iterator <_Mylist> –

+0

的成員你確定你做了'm_WayPoints.end()'嗎?因爲如果是這樣的話,那個錯誤沒有意義。 – JaredC

+0

我第一次寫錯碼(錯誤的變量)。謝謝。我不知道原始源代碼如何工作給作者? –

3

您無法將迭代器與NULL進行比較,這就是爲什麼您會收到這些錯誤。而且據我所知,除非將其設置爲某種東西,否則無法檢查是否和迭代器指向某個東西。將它設置爲end()將使它成爲一種NULL迭代器(因爲end()是容器中的最後一個元素,所以它基本上指向無)。

+0

設置它做什麼'結束? (否則,確實,似乎沒有辦法確定迭代器是否有效 - http://stackoverflow.com/questions/824157/how-to-check-whether-stl-iterator-points-at-any-anything) – Mat

+0

贊@JaredC說,我看不到你所有的代碼,但是如果你的類中有任何容器,那麼在你的構造函數中設置迭代器到最後。 – prajmus

0

我的原始源代碼的副本有點不同的,那麼你的...

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

TBL:在我有代碼的副本,它沒有測試迭代器,但它是測試迭代器指向什麼。不幸的是,我得到的是同樣的錯誤,你是。

+0

這是一個答案? –

+0

我也碰到過這個。你從哪裏得到你的源代碼副本?我從http://samples.jbpub.com/9781556220784/Buckland_SourceCode.zip取得它。我的問題與問題中的相同(即沒有「*」)。 – Chris

相關問題