c++ - VS2010 中未解析的外部符号

标签 c++ visual-c++

我正在为支持 decPrio 操作的堆编写代码。但是当我使用代码时出现 Unresolved external symbol 错误。

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:未解析的外部符号“public: void __thiscall FibonacciHeap<int,int,struct std::less<int> >::decPrio(class Node<int,int> *,int const &)” (?decPrio@?$FibonacciHeap@HHU?$less@H@std@@@@QAEXPAV?$Node@HH@@ABH@Z)在函数 _main 中引用

最佳答案

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)
{

关于c++ - VS2010 中未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22778492/

相关文章:

c++ - 具有 alpha 和 glColor4f 的 OpenGL 纹理,glColor4f 影响纹理

c++ - C++ 成员函数中的 "if (!this)"有多糟糕?

visual-c++ - TaskDialog 在 Visual C++ 中始终位于顶部

c++ - 我需要一个(有序的)集合,我可以在其中快速检索成员元素的相对索引

c++ - 将两个图像拼接在一起的问题

c++ - 向某些屏幕位置写入宽字符时,ncurses 会崩溃

c++ - MFC 扩展 CFileDialog

sockets - 如何在fiddler中捕获套接字编程的发送和接收请求

visual-studio - 错误 : this template attempted to load component assembly 'Microsoft. VisualStudio.Universal.TemplateWizards,版本=15.0.0.0

c++ - 无法使用regex c++ 11 std在Windows中运行使用minGW编译的程序