1

Complete error message:

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

I am very new to [V]C++ world. I was reading Programing Game AI by Example book and trying to study/analyze the source code which is available in publishers site.

It seems like entire source code is written in VS8 but I am using VS12 Express edition. The project conversion seems have no problems expect 4 warnings which I am getting for all the projects (see below).

But the problem is I am getting a compile error which seems to me, with basic knowledge I have is with operator overloading of a strongly typed list, but I am not sure if its true and I have no clue how to fix it if its true.

Code line for error#1:

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

Declaration of the problem variable:

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

Extended code snippet including constructors:

//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());}

Now I am not sure where to go to after this, but the list and iterator definitions are inside the WindowsUtils.h file.

I am not pasting remaining errors which are same, however you can access the entire Path.h file here

Can someone tell me how to fix this? I am always scared of c++, particularly with vc++, but I can fix it by myself if some one guides me what the issue is and approach to fix it

Errors

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

Just in case if this matters, below is the warnings I keep get for every project in the book's source code

*Common solution conversion warnings: * (note: not the same project as above)

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). 
dejjub-AIS
  • 1,501
  • 2
  • 24
  • 50

3 Answers3

3

You can't compare an iterator to NULL, this is why you get those errors. And as much as I know, there's no way to check if and iterator points at something unless you set it to something. Setting it to end() will make it kind of NULL iterator (as end() is the element after the last in containers so it basically points to nothing).

prajmus
  • 3,171
  • 3
  • 31
  • 41
  • Setting it do `end` of what? (otherwise, indeed, it appears there's no way of determining if an iterator is valid - http://stackoverflow.com/questions/824157/how-to-check-whether-stl-iterator-points-at-anything) – Mat Jan 12 '13 at 14:20
  • Like @JaredC said, I can't see all of your code, but if you have any container in your class, set the iterator to it's end in your constructor. – prajmus Jan 12 '13 at 14:29
0

comparing an iterator to NULL is not valid:

assert(curWaypoint != NULL);

I haven't looked at all of your code, but perhaps you mean to compare this to end():

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

You initialize curWaypoint in your constructor so this should work as you intend.

JaredC
  • 5,150
  • 1
  • 20
  • 45
0

My copy of the original source code is a little different then yours ...

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

TBL: In the copy of the code that I have, it is not testing the iterator, but it is testing what the iterator is pointing at. Unfortunately, I am getting the same error that you are.

user1564349
  • 79
  • 1
  • 2
  • I just ran into this, too. Where did you get your copy of the source? I fetched it from http://samples.jbpub.com/9781556220784/Buckland_SourceCode.zip. Mine is the same as in the question (i.e., w/o the "*"). – Chris May 31 '13 at 02:44