c++ - 使用 BOOST 时出现 LNK 错误 1561

标签 c++ boost visual-studio-2012 linker-errors

我正在尝试创建一个 avl 树,然后使用 boost 来检查我创建的内容是否正常工作。但是,在我所有的 boost 测试用例中,我没有一个主要的(我认为这是导致问题的问题)。这是我的 avl.hpp 我对 C++ 有点陌生。

template <typename T>
class avlTreeNode
{
public:
    // data in the node
    T nodeValue;
    // pointers to the left and right children of the node
    avlTreeNode<T> *left;
    avlTreeNode<T> *right;
    int balanceFactor;
    // CONSTRUCTOR
    avlTreeNode (const T& item, avlTreeNode<T> *lptr = NULL,
        avlTreeNode<T> *rptr = NULL, int bal = 0):
    nodeValue(item), left(lptr), right(rptr), balanceFactor(bal)
    {
    }
};

const int leftheavy = -1;
const int balanced = 0;
const int rightheavy = 1;

template <typename T>
class avlTree
{
public:
    // CONSTRUCTORS, DESTRUCTOR, ASSIGNMENT
    // constructor. initialize root to NULL and size to 0
    avlTree();
    ~avlTree();

    typedef T* iterator;
    typedef T const* const_iterator;
    // constructor. insert n elements from range of T* pointers4
    avlTree(T *first, T *last);
    // search for item. if found, return an iterator pointing
    // at it in the tree; otherwise, return end()
    iterator find(const T& item);
    // search for item. if found, return an iterator pointing
    // at it in the tree; otherwise, return end()
    const_iterator find(const T& item) const;
    // indicate whether the tree is empty
    int empty() const;
    // return the number of data items in the tree
    int size() const;
    // give a vertical display of the tree .
    void displayTree(int maxCharacters) const;
    // insert item into the tree
    //std::pair<iterator, bool> insert(const T& item);
    // insert a new node using the basic List operation and format
    //std::pair<iterator, bool> insert(const T& item);
    // delete all the nodes in the tree
    void clear();
    // constant versions
    iterator begin();
    iterator end();
    const_iterator begin() const;
    const_iterator end() const;

///////////////////////////////////////////////////////////
//when I created this it started giving me the lnk 1561 error 
    std::pair<iterator,bool> insert(const T& item)
    {
        avlTree<T>::iterator iter;
        // quietly return if item is already in the tree
        if ((iter = find(item)) != end() )
            return std::pair<iterator,bool>(iter,false);
        // declare AVL tree node pointers.
        avlTreeNode<T> *treeNode = root,*newNode;
        // flag used by AVLInsert to rebalance nodes
        bool reviseBalanceFactor = false;
        // get a new AVL tree node with empty pointer fields
        newNode = getavlTreeNode(item,NULL,NULL);
        // call recursive routine to actually insert the element
        avlInsert(treeNode, newNode, reviseBalanceFactor);
        // assign new values to data members root, size and current
        root = treeNode;
        treeSize++;
        return std::pair<iterator, bool> (iterator(newNode), true);
    }

private:
    // pointer to tree root
    avlTreeNode<T> *root;
    // number of elements in the tree
    int treeSize;
    // allocate a new tree node and return a pointer to it
    avlTreeNode<T> *getavlTreeNode(const T& item,
        avlTreeNode<T> *lptr,avlTreeNode<T> *rptr);
    // used by copy constructor and assignment operator
    avlTreeNode<T> *copyTree(avlTreeNode<T> *t);
    // delete the storage occupied by a tree node
    void freeavlTreeNode(avlTreeNode<T> *p);
    // used by destructor, assignment operator and clear()
    void deleteTree(avlTreeNode<T> *t);
    // locate a node item and its parent in tree. used by find()
    avlTreeNode<T> *findNode(const T& item, 
        avlTreeNode<T>* & parent) const;
    // member functions to insert and erase a node
    void singleRotateLeft (avlTreeNode<T>* &p);
    void singleRotateRight (avlTreeNode<T>* &p);
    void doubleRotateLeft (avlTreeNode<T>* &p);
    void doubleRotateRight (avlTreeNode<T>* &p);
    void updateLeftTree (avlTreeNode<T>* &tree,
        bool &reviseBalanceFactor);
    void updateRightTree (avlTreeNode<T>* &tree,
        bool &reviseBalanceFactor);
};

最佳答案

在您的 cpp 文件的顶部,定义 BOOST_TEST_MAIN。用于单元测试库自动生成main函数。

例如:

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include "avl.hpp"

BOOST_AUTO_TEST_CASE( test )
{
    // ...
}

关于c++ - 使用 BOOST 时出现 LNK 错误 1561,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15166336/

相关文章:

c++ - 将二维数组转换为一维数组以绘制线条

C++ - 声明结构和类时不允许使用不完整类型

c++ - Spirit X3,指的是之前匹配的值

c++ - GLEW 和 VS 2012 : unresolved external symbols

windows - 由于 MSVCR110.dll,MS Visual Studio 2012 Ultimate 无法启动

c++ - 带有函数指针参数的模板类

c++ - 类内和类外的 friend 功能,有什么区别?

c++ - 如何在端口 80 上运行 Boost.Asio 服务器?

c++ - Boost Spirit 可选解析器和回溯

VB.NET 2012 在属性获取上设置属性