C++调试有关问题,求教
C++调试问题,求教!
我这里是用A*算法求迷宫最短路径,
先定义一个机构如下:
typedef struct {
int gn;
int fn;
int flag; //1——in open; 2——in close
}GFN;
map <int ,GFN*> gmap; 定义一个map来存储gn,fn的信息
让后定义两个表open、和close
list <int> open;
list <int> close;
在这三个结构中,整型元素都是n,像数据库中一样来索引。通过open,close中的元素在gmap中查找到n的信息。
open表是一个有序表,是按照gmap表中的fn的增排序,在对open表排序时自己写了一个函数来实现,
如下:
bool opensort(int n1,int n2)
{
map <int,GFN*> ::iterator pos1,pos2;
pos1 = gmap.find(n1);
pos2 = gmap.find(n2);
return pos1-> second-> fn < pos2-> second-> fn;
}
在排序时:sort(open.begin(),open.end(),opensort);
编译时总出现错误,
如:
c:\program files\microsoft visual studio\vc98\include\algorithm(592) : error C2784: '_D __cdecl std::operator -(const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> &) ' : could not deduce temp
late argument for 'const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> & ' from 'class std::list <int,class std::allocator <int> > ::iterator '
c:\program files\microsoft visual studio\vc98\include\algorithm(589) : see reference to function template instantiation 'void __cdecl std::_Sort_0(class std::list <int,class std::allocator <int> > ::iterator,class std::list <int,class std::alloc
ator <int> > ::iterator,bool (__cdecl *)(int,int),int *) ' being compiled
/***********************************************************/
//源程序如下:
#include <iostream>
#include <strstream>
#include <list>
#include <map>
#include <algorithm>
using namespace std;
#define MAZE_ROW 9
#define MAZE_COL 7
char maze[MAZE_ROW][MAZE_COL]={
' ', ' ', ' ', '# ', '# ', '# ', '# ',
'# ', '# ', ' ', '# ', '# ', '# ', '# ',
' ', '# ', ' ', '# ', '# ', '# ', '# ',
' ', '# ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', '# ', '# ', '# ', '# ', ' ',
'# ', ' ', ' ', ' ', ' ', '# ', ' ',
'# ', '# ', ' ', '# ', ' ', '# ', ' ',
' ', ' ', ' ', ' ', '# ', '# ', ' ',
' ', ' ', '# ', ' ', ' ', '# ', ' ',
我这里是用A*算法求迷宫最短路径,
先定义一个机构如下:
typedef struct {
int gn;
int fn;
int flag; //1——in open; 2——in close
}GFN;
map <int ,GFN*> gmap; 定义一个map来存储gn,fn的信息
让后定义两个表open、和close
list <int> open;
list <int> close;
在这三个结构中,整型元素都是n,像数据库中一样来索引。通过open,close中的元素在gmap中查找到n的信息。
open表是一个有序表,是按照gmap表中的fn的增排序,在对open表排序时自己写了一个函数来实现,
如下:
bool opensort(int n1,int n2)
{
map <int,GFN*> ::iterator pos1,pos2;
pos1 = gmap.find(n1);
pos2 = gmap.find(n2);
return pos1-> second-> fn < pos2-> second-> fn;
}
在排序时:sort(open.begin(),open.end(),opensort);
编译时总出现错误,
如:
c:\program files\microsoft visual studio\vc98\include\algorithm(592) : error C2784: '_D __cdecl std::operator -(const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> &) ' : could not deduce temp
late argument for 'const class std::reverse_iterator <_RI,_Ty,_Rt,_Pt,_D> & ' from 'class std::list <int,class std::allocator <int> > ::iterator '
c:\program files\microsoft visual studio\vc98\include\algorithm(589) : see reference to function template instantiation 'void __cdecl std::_Sort_0(class std::list <int,class std::allocator <int> > ::iterator,class std::list <int,class std::alloc
ator <int> > ::iterator,bool (__cdecl *)(int,int),int *) ' being compiled
/***********************************************************/
//源程序如下:
#include <iostream>
#include <strstream>
#include <list>
#include <map>
#include <algorithm>
using namespace std;
#define MAZE_ROW 9
#define MAZE_COL 7
char maze[MAZE_ROW][MAZE_COL]={
' ', ' ', ' ', '# ', '# ', '# ', '# ',
'# ', '# ', ' ', '# ', '# ', '# ', '# ',
' ', '# ', ' ', '# ', '# ', '# ', '# ',
' ', '# ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', '# ', '# ', '# ', '# ', ' ',
'# ', ' ', ' ', ' ', ' ', '# ', ' ',
'# ', '# ', ' ', '# ', ' ', '# ', ' ',
' ', ' ', ' ', ' ', '# ', '# ', ' ',
' ', ' ', '# ', ' ', ' ', '# ', ' ',