首页 > 解决方案 > 未定义的对 `BST 的引用::BST()'

问题描述

我收到这些错误

C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x1b): 未定义对BST<char>::BST()' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x1eb): undefined reference toBST::insert(char const&)' C:\Users\SDRav\AppData\Local 的引用\Temp\ccCy0RiX.o:driver.cpp:(.text+0x228): 未定义对BST<char>::traversePreorder(BSTNode<char>*)' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x263): undefined reference toBST::search(char const&) const' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver 的引用。 cpp:(.text+0x32b): 未定义对BST<char>::deleteNode(char const&)' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x419): undefined reference toBST::leafCount(BSTNode*)' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x47c) 的引用:未定义参考BST<char>::search(char const&) const' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x4d5): undefined reference toBST::getSiblings(char const&)' collect2.exe: error: ld returned 1 exit status

但我不知道为什么....我的猜测是链接但我检查了标题但我仍然看不到它

我的驱动程序.cpp(主要)

#include <iostream>

#include <iomanip>
#include "BST.h"
using namespace std;

int main()
{

    BST<char> op1;
    int action = 0;
    int numInsert = 0;
    char value;

cout<<"-------------------- MENU ----------------------"
        <<endl<<"1. Insert node(s)"
        <<endl<<"2. Traverse Preorder"
        <<endl<<"3. Search BST"
        <<endl<<"4. Delete node"
        <<endl<<"5. Leaf Count"
        <<endl<<"6. Sibling of a node"
        <<endl<<"7. Quit"
        <<endl<<"Please ent

 switch (action)
        {
            case 1:
                cout << "\n How many values would you liek to insert to a BST? ";
                cin>>numInsert;
                for(int i =0; i<numInsert;i++){
                    cout<<"What value would you like to insert to the list: ";
                    cin >> value;
                    op1.insert(value); //check
                }    
                break;
   ...

}

--- BST.h ---

#include <iostream>
#include "BSTNode.h"

using namespace std;

#ifndef BINARY
#define BINARY

template <typename DataType>

class BST
{
    public:
        BST();
        // ~BST();

        bool empty() const;
        /*------------------------------------------------------------------------
            Check if BST is empty.

            Precondition:  None.
            Postcondition: Returns true if BST is empty and false otherwise.
        -----------------------------------------------------------------------*/
        void insert(const DataType & item);
        void traversePreorder(BSTNode<DataType> * startPoint);
        bool search(const DataType & item)const;
        bool deleteNode(const DataType & item);
        int leafCount(BSTNode<DataType> * startPoint);
        DataType getSiblings(const DataType & item);




    private:
        BSTNode<DataType> * treeRoot;
        typedef BSTNode<DataType> * BSTNodePointer; 
        void search2(const DataType & item, bool & found,  BSTNodePointer & locptr, BSTNodePointer & parent) const;


};

请帮忙

标签: c++binarybinary-treebinary-search-treebinary-search

解决方案


推荐阅读