致命错误lnk11201未解决的外部
Fatal Error LNK 1120 1 Unresolved External
我想弄清楚为什么我的代码不编译,这说未解决的外部。我正试图找出问题是什么,为什么它不能编译。
实际错误:主:错误LNK2001:未解析的外部符号"public: virtual bool__thiscall BST,类std::allocator>>::isThere(类std:: basic_string类std::分配器>)"(isThere@ BST@V美元? basic_string@DU ?美元$ char_traits@D@std@@V ? allocator@D@2@@std@@@@UAE_NV美元? basic_string@DU美元? char_traits@D@std@@V美元? allocator@D@2@@std@@@Z美元)1> c: jordin 文档 visual studio用户2012 ConsoleApplication16 项目调试 ConsoleApplication16.exe:致命错误LNK1120: 1个未解决的外部
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include "BST.h"
SearchableADT<string> *dictionary = new BST<string>;
int main()
{
char choice = 'z';
string tempdata,
fileloc;
cout<<"Welcome to Jordin Ray's Spell Check Applicationn"
<<"Please pick a tree typen"
<<"'b' -Binary Search Treen"
<<"'a' -AVL treen"
<<"'h' -hash tablen";
cin>>choice;
cout<<"Please give the exact location of the file for downloadn";
cin>>fileloc;
if(choice == 'b')
{
dictionary->loadFromFile(fileloc);
char ch = 'z';
while(ch != 'q')
{
string word = "";
if(ch == 'e')
{
cout<<"Please enter the word you would like to search forn";
cin>>word;
dictionary->isThere(word);
}
else if (ch == 'p')
{
cout<<"Please enter the partial word you would like to look for with a '?' where the missing letter is: n"
<<"Ex. - '?nd' will search for words in the dictionary that have those last two lettersn";
// dictionary->partialIsThere(word);
}
else if (ch == 'c')
{
//dictionary.clear();
}
else if (ch == 's')
{
int entries;
entries = dictionary->numEntries();
cout<<"nThe amount of entries logged in the database is: "<<entries<<".n";
}
cout<<"Would you like to:n"
<<"Clear the dictionary - 'c'n"
<<"Check for an entry - 'e'n"
<<"Check for a partial entry - 'p'n"
<<"Report Statistics - 's'n"
<<"Quit - 'q'";
cin>>ch;
}//end of while loop
}
return 0;
}//end of main()
BST.h
#ifndef BST_H
#define BST_H
#pragma once
#include "SearchableADT.h"
#include <cstring>
using namespace std;
template <typename T>
class BST : public SearchableADT<T>
{
private:
struct t_node
{
string data;
t_node *L;
t_node *R;
};
int numnodes;
t_node* head;
t_node* cPTR; //current pointer
t_node* pPTR; //parent pointer
t_node* tPTR; //temporary pointer
public:
BST(void);
~BST(void);
int loadFromFile(string filename);
//void clear(void);
void insertEntry(T info);
void deleteEntry(T info);
bool isThere(T info);
int numEntries(void);
//needed for comparison to AVL
int BST<T>::height(t_node* tPTR);
}; // end of class BST
//constructor
template <typename T>
BST<T>::BST(void)
{
head = NULL;
numnodes = 0;
}
//destructor
template <typename T>
BST<T>::~BST(void)
{
this->clear();
}
template <typename T>
void BST<T>::insertEntry(T info)
{
t_node* t = new t_node;
t->data = info;
t->L = NULL;
t->R = NULL;
pPTR = NULL;
if(head == NULL)
head = t;
else
{
t_node* cPTR; //current pointer
cPTR = head;
//checks to see if the data just entered is
//greater than the head
while(cPTR)
{
pPTR = cPTR;
if( t->data > cPTR->data)
cPTR = cPTR->R;
else
cPTR = cPTR->L;
}
//checks to see if the data just entered is
// less than the parent data that was
// set equal to cPTR;
if(t->data < pPTR->data)
{
pPTR->L = t;
}
else
{
pPTR->R = t;
}
}
} //end of insertEntry()
template <typename T>
void BST<T>::deleteEntry(T info)
{
//i use this as an example of abstraction
//after using this function the cPTR and pPTR are already pointing to the data needed to be found
if(!isThere(info))
{
cout<<"The data: '"<<info<<"' could not be found in the ADT, sorry!n";
return;
}
//one has to account for all possibilities when deleting data
//1.) - Removing just a leaf node (no children) **easy
//2.) - Removing a leaf node with 1 child **medium
//3.) - Removing a leaf node with 2 children **hard
//case 1
if( cPTR->L == NULL && cPTR ->R == NULL)
{
if(pPTR-> L == cPTR)
pPTR->L = NULL;
else
pPTR->R = NULL;
delete cPTR;
return;
}//end of case 1
//case 2
else if((cPTR->L == NULL && cPTR->R != NULL) ||
(cPTR->L != NULL && cPTR->R == NULL))
{
//if the left data of cptr has data and the right data is NULL
if(cPTR->L != NULL && cPTR->R == NULL)
{
if(pPTR->L == cPTR)
{
pPTR->L = cPTR->R;
delete cPTR;
}
else
{
pPTR->R = cPTR->L;
delete cPTR;
}
}
else //right child present, and left child is NULL
{
if(pPTR->L == cPTR)
{
pPTR->L = cPTR->R;
delete cPTR;
}
else
{
pPTR->R = cPTR->R;
delete cPTR;
}
}
//case 3
if((cPTR->L != NULL && cPTR->R != NULL))
{
tPTR=cPTR->R;
//if the right node doesn't have a right leaf or left leaf, delete that node
if((tPTR->L == NULL && tPTR->R == NULL))
{
cPTR = tPTR;
delete cPTR;
cPTR->R = NULL;
}
else
{
if(tPTR->L != NULL)
{
t_node* secPTR;
secPTR = tPTR->L;
//cycle through left nodes until you find the lowest left node
while(secPTR->L != NULL)
{
secPTR = secPTR->L;
}
//because you're only setting the data equal to eachother the cPTR keeps its left and right nodes
//therefore it correctly replaces the data without unwanted loss of other information
cPTR->data = secPTR->data;
delete secPTR;
cPTR->L = NULL;
}
else
{
cPTR->data = tPTR->data;
cPTR->R = tPTR->R;
delete tPTR;
}
}
}
}
}//end of deleteEntry() function
template <typename T>
int BST<T>::numEntries(void)
{
cout << "Tree Height: " << height(head) << endl;
return numnodes;
}
template <typename T>
int BST<T>::loadFromFile(string filename)
{
int count = 0;
string tempdata;
ifstream fin(filename);
if(!fin)
{
cout<< "Error: Could no open filen";
count--;
}
while(fin)
{
fin>>tempdata;
if(fin)
{
insertEntry(tempdata);
count++;
}
}
fin.close();
return count;
}//end of loadFromFile() function
template <typename T>
int BST<T>::height(t_node* tPTR)
{
if (head == NULL)
return -1;
else
return 1 + max(height(tPTR->L), height(tPTR->R));
tPTR=head;
}
#endif
SearchableADT.h
#ifndef SEARCHABLEADT_H
#define SEARCHABLEADT_H
#include <string>
using namespace std;
template <typename T>
class SearchableADT
{
public:
virtual int loadFromFile(string filename) = 0;
//virtual void clear(void) = 0;
virtual void insertEntry(T value) = 0;
virtual void deleteEntry(T value) = 0;
virtual bool isThere(T value) = 0 ;
virtual int numEntries(void) = 0;
};
#endif
需要定义BST::isThere( T info )
函数
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 节俭并发:未解决的外部问题
- 未解决的外部链接问题
- Visual Studio 2017 中的 QtMetaObject 未解决的外部错误
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 解释未解决的外部C++
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 函数路径追加上未解决的外部符号错误
- Lapack函数DGTSV通过C /Visual Studio提供未解决的外部符号
- 运算符过载上未解决的外部符号
- qfilesystemwatcher未解决的外部
- C 未解决的外部符号(公共静态INT)
- MIDL COM库中未解决的外部符号
- 未解决的外部符号sf ::带有SFML的时间
- C++编译错误LNK2019:未解决的外部符号错误
- VTK / ITK/ QT - 未解决的外部符号错误 (LNK2001)
- 未解决的外部包括AUX_KLIB内核库
- 错误LNK1120:未解决的外部
- QT创建者:简单程序未解决的外部符号和外部符号错误
- 编译示例 Cinder 项目时存在大量未解决的外部问题