今天真的是十分郁闷,遇到这个名为error C2039: “iterator_category”: 不是“***”的成员,上网谷哥、度娘了一番,得到的结果全是说可能是用的某个名字与库中的重合了,结果试了整整的一个下午加晚上,验证了所有的名字之后,发现问题不是这样的!!!
改后代码:
//vector<Degree> deg;//用来描述从源点source到v的最短路径上权值的上界
Degree* deg = new Degree[MAXSIZE];
priority_queue<Degree, vector<Degree>, cmp> Q(deg, deg + MAXSIZE);
vector<Degree> deg;//用来描述从源点source到v的最短路径上权值的上界 priority_queue<Degree, vector<Degree>, cmp> Q(deg[0], deg[MAXSIZE];错误提示:
1>------ 已启动生成: 项目: Dijkstra, 配置: Debug Win32 ------ 1> main.cpp 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(373): error C2039: “iterator_category”: 不是“Degree”的成员 1> c:\users\chenhq\desktop\dijkstra\dijkstra\degree.h(4) : 参见“Degree”的声明 1> d:\program files\microsoft visual studio 10.0\vc\include\vector(550): 参见对正在编译的类 模板 实例化“std::iterator_traits<_Iter>”的引用 1> with 1> [ 1> _Iter=Degree 1> ] 1> d:\program files\microsoft visual studio 10.0\vc\include\queue(247): 参见对正在编译的函数 模板 实例化“std::vector<_Ty>::vector<_Iter>(_Iter,_Iter)”的引用 1> with 1> [ 1> _Ty=Degree, 1> _Iter=Degree 1> ] 1> c:\users\chenhq\desktop\dijkstra\dijkstra\dijkstra.h(20): 参见对正在编译的函数 模板 实例化“std::priority_queue<_Ty,_Container,_Pr>::priority_queue<Degree>(_Iter,_Iter)”的引用 1> with 1> [ 1> _Ty=Degree, 1> _Container=std::vector<Degree>, 1> _Pr=cmp, 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(373): error C2146: 语法错误: 缺少“;”(在标识符“iterator_category”的前面) 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(373): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(373): error C2602: “std::iterator_traits<_Iter>::iterator_category”不是“std::iterator_traits<_Iter>”基类的成员 1> with 1> [ 1> _Iter=Degree 1> ] 1> d:\program files\microsoft visual studio 10.0\vc\include\xutility(373) : 参见“std::iterator_traits<_Iter>::iterator_category”的声明 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(373): error C2868: “std::iterator_traits<_Iter>::iterator_category”: 非法的 using 声明语法;应输入限定名 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(374): error C2039: “value_type”: 不是“Degree”的成员 1> c:\users\chenhq\desktop\dijkstra\dijkstra\degree.h(4) : 参见“Degree”的声明 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(374): error C2146: 语法错误: 缺少“;”(在标识符“value_type”的前面) 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(374): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(374): error C2602: “std::iterator_traits<_Iter>::value_type”不是“std::iterator_traits<_Iter>”基类的成员 1> with 1> [ 1> _Iter=Degree 1> ] 1> d:\program files\microsoft visual studio 10.0\vc\include\xutility(374) : 参见“std::iterator_traits<_Iter>::value_type”的声明 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(374): error C2868: “std::iterator_traits<_Iter>::value_type”: 非法的 using 声明语法;应输入限定名 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(375): error C2039: “difference_type”: 不是“Degree”的成员 1> c:\users\chenhq\desktop\dijkstra\dijkstra\degree.h(4) : 参见“Degree”的声明 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(375): error C2146: 语法错误: 缺少“;”(在标识符“difference_type”的前面) 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(375): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(375): error C2602: “std::iterator_traits<_Iter>::difference_type”不是“std::iterator_traits<_Iter>”基类的成员 1> with 1> [ 1> _Iter=Degree 1> ] 1> d:\program files\microsoft visual studio 10.0\vc\include\xutility(375) : 参见“std::iterator_traits<_Iter>::difference_type”的声明 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(375): error C2868: “std::iterator_traits<_Iter>::difference_type”: 非法的 using 声明语法;应输入限定名 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(377): error C2039: “pointer”: 不是“Degree”的成员 1> c:\users\chenhq\desktop\dijkstra\dijkstra\degree.h(4) : 参见“Degree”的声明 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(377): error C2146: 语法错误: 缺少“;”(在标识符“pointer”的前面) 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(377): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(377): error C2602: “std::iterator_traits<_Iter>::pointer”不是“std::iterator_traits<_Iter>”基类的成员 1> with 1> [ 1> _Iter=Degree 1> ] 1> d:\program files\microsoft visual studio 10.0\vc\include\xutility(377) : 参见“std::iterator_traits<_Iter>::pointer”的声明 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(377): error C2868: “std::iterator_traits<_Iter>::pointer”: 非法的 using 声明语法;应输入限定名 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(378): error C2039: “reference”: 不是“Degree”的成员 1> c:\users\chenhq\desktop\dijkstra\dijkstra\degree.h(4) : 参见“Degree”的声明 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(378): error C2146: 语法错误: 缺少“;”(在标识符“reference”的前面) 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(378): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(378): error C2602: “std::iterator_traits<_Iter>::reference”不是“std::iterator_traits<_Iter>”基类的成员 1> with 1> [ 1> _Iter=Degree 1> ] 1> d:\program files\microsoft visual studio 10.0\vc\include\xutility(378) : 参见“std::iterator_traits<_Iter>::reference”的声明 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\xutility(378): error C2868: “std::iterator_traits<_Iter>::reference”: 非法的 using 声明语法;应输入限定名 1> with 1> [ 1> _Iter=Degree 1> ] 1>d:\program files\microsoft visual studio 10.0\vc\include\vector(550): error C2664: “void std::vector<_Ty>::_Construct<_Iter>(_Iter,_Iter,std::_Int_iterator_tag)”: 不能将参数 3 从“int”转换为“std::_Int_iterator_tag” 1> with 1> [ 1> _Ty=Degree, 1> _Iter=Degree 1> ] 1> 无构造函数可以接受源类型,或构造函数重载决策不明确 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
后来,再看回错误的提示,关注到了这个
1> with 1> [ 1> _Iter=Degree 1> ]出现的频率非常之高,我想是不是参数哪里出错了!!坑爹啊,真的是啊
因为是第一次学着用“优先级队列”,还没弄清楚,但是现在知道了一点,后面的参数是要为指针