我正在编写支持decPrio操作的堆的代码。但是当我使用代码时,我得到了未解决的外部符号错误。
template< typename PRIO, typename VALUE>
class Node;
template< typename PRIO, typename VALUE, typename CMP = std::less<PRIO> >
class FibonacciHeap{
//Interface:
//a typedef for a type "item", which acts as a pointer to an element in the queue
//(item is used below in various methods).
public:
typedef Node<PRIO,VALUE>* item;
typedef int size_t;
CMP cmp;
private:
item m_roots;
int item_count;
public:
void decPrio(item it, const PRIO &prio);
item insert(const PRIO &prio, const VALUE &value);
private:
void link(item x,item y);
void cut(item x,item y);
void cascadeCut(item y);
};
template< typename PRIO, typename VALUE>
class Node{
friend class FibonacciHeap<PRIO,VALUE>;
int degree;
bool marked;
Node<PRIO,VALUE>* parent;
Node<PRIO,VALUE>* child;
Node<PRIO,VALUE>* left;
Node<PRIO,VALUE>* right;
public:
PRIO prio;
VALUE value;
Node(PRIO p,VALUE v) :
degree(0),marked(0), parent(NULL),child(NULL),left(NULL),right(NULL),prio(p),value(v) {}
};
template<typename PRIO,typename VALUE,typename CMP>
void decPrio(typename FibonacciHeap<PRIO,VALUE,CMP>::item it, const PRIO &prio)
{
if(m_roots==NULL)
return;
if(it==NULL)
return;
if(!cmp(prio,it->prio))
return;
it->prio=prio;
item y =it->parent;
if(y!=NULL && cmp(it->prio,y->prio))
{
cut(it,y);
cascadeCut(y);
}
if(cmp(it->prio,m_roots->prio))
m_roots=it;
}
这是我的主要代码
#include<stdio.h>
#include "myfib.h"
using namespace std;
int main(){
FibonacciHeap<int,int> f;
FibonacciHeap<int,int>::item temp;
temp=f.insert(30,1);
f.decPrio(temp,2);
return 0;
}
我收到错误消息:
错误LNK2019:未解析的外部符号&#34; public:void __thiscall FibonacciHeap<int,int,struct std::less<int> >::decPrio(class Node<int,int> *,int const &)
&#34; (?decPrio @?$ FibonacciHeap @HHU?$ less @ H @ std @@@@ QAEXPAV?$ Node @ HH @@ ABH @ Z)在函数_main中引用
答案 0 :(得分:0)
template<typename PRIO,typename VALUE,typename CMP>
void decPrio(typename FibonacciHeap<PRIO,VALUE,CMP>::item it, const PRIO &prio)
{
应该是
template<typename PRIO,typename VALUE,typename CMP>
void FibonacciHeap<PRIO,VALUE,CMP>::decPrio(Node<PRIO,VALUE>* it, const PRIO &prio)
{