2014-01-12 29 views
-3

我创建链接列表,它没有问题,并运行。另外我必须包括二叉树。和它给我这个错误LNK2019无法解析的外部符号。创建二叉树

1> Generating Code... 1> Skipping... (no relevant changes detected) 1> main.cpp 1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall SDI::BinaryTree::insert(int)" ([email protected]@[email protected]@[email protected]) referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall SDI::BinaryTree::preOrder(void)" ([email protected]@[email protected]@QAEHXZ) referenced in function _main 1>C:\Users\Muugii\Documents\Visual Studio 2013\LinkedList\Debug\LinkedList.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

BinaryTree.h

IFNDEF SDI_BINARYTREE

定义SDI_BINARYTREE

包括

namespace SDI 
{ 
    class BinaryTree 
    { 
     class BTNode 
     { 
     public: 
      int data; 
      BTNode *left; 
      BTNode *right; 
     }; 

    public: 
     BinaryTree(); 
     ~BinaryTree(); 

     int insert(const int value); 
     int preOrder() const; 
     int clearTree(); 

    private: 

     BTNode *headPtr; 

     int insert(const int value, BTNode *leaf); 
     int clearTree(BTNode *leaf) const; 
     int preOrder(BTNode *leaf) const; 

    }; 
}; 

#endif 

BinaryTree.cpp

Main.cpp的

#include <string> 
#include <iostream> 
#include "Linkedlist.h" 
#include "BinaryTree.h" 

using namespace std; 

int main(int argc, const char *argv[]) 
{ 

    SDI::LinkedList myList; 
    //SDI::BinaryTree myTree; 
    int inp; 

.... 

if (inp2 == 'a') 
       { 
        int num; 

         cout << "\nPlease enter a value to add: "; 
         cin >> num; 
         myTree.insert(num); 
         cout << "\n\t\tValue has been successfully saved\n\n\n"; 


       } 

我试图寻找在线,找不到任何。这将是很大的帮助。

+3

是什么阻止您在发布之前修改格式? –

+1

好吧,它告诉你在那里,“公共:int __thiscall SDI :: BinaryTree :: preOrder(void)”。您没有该方法的实现。 – OldProgrammer

回答

0

当我看到你有名字插入两个功能。并且第一个

int insert(const int value); 

只声明但未定义。

+0

谢谢谢谢,我很抱歉大家,我刚开始编码。请不要那么粗鲁。 – Dyrus

+0

由于@DietmarKühl说你还需要定义函数preOrder –

0

错误信息的哪一部分对您不清楚?它明确指出,你还没有实现两个你的方法:

int SDI::BinaryTree::insert(const int value) { 
    return 0; // the implementation probably needs some patching up 
} 
int SDI::BinaryTree::preOrder() const { 
    return 0; // as does this one 
} 
相关问题