c++ - LNK 1120 + LNK2019 Error -


i'm working on c++ project , have never used header files before, trying build project throwing several linker errors, have no idea or how go fixing them!

the errors follows:

error 4 error lnk1120: 3 unresolved externals c:\users\stephen\downloads\08227_acw2_testharness_12-13\08227_acw2_testharness_12-13\debug\08227_acw.exe 1 1 08227_acw

error 3 error lnk2019: unresolved external symbol "public: bool __thiscall arraystorage::exists(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?exists@arraystorage@@qae_nv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@@z) referenced in function _main c:\users\stephen\downloads\08227_acw2_testharness_12-13\08227_acw2_testharness_12-13\main.obj 08227_acw

error 2 error lnk2019: unresolved external symbol "public: bool __thiscall arraystorage::stdexists(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?stdexists@arraystorage@@qae_nv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@@z) referenced in function _main c:\users\stephen\downloads\08227_acw2_testharness_12-13\08227_acw2_testharness_12-13\main.obj 08227_acw

error 1 error lnk2019: unresolved external symbol "public: bool __thiscall linkedliststorage::exists(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?exists@linkedliststorage@@qae_nv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@@z) referenced in function _main c:\users\stephen\downloads\08227_acw2_testharness_12-13\08227_acw2_testharness_12-13\main.obj 08227_acw

from reading around sort of linker error, have absolutely no idea actual problem is. don't know whether putting code help, if needed let me know , i'll put up.

thanks in advance!

edit:

the header files:

arraystorage.h

#ifndef mao #define mao  #include <fstream> #include <string> #include <iostream> #include <algorithm>   using namespace std;   class arraystorage  { private:     string* storagearray;     int asize; public:     void read(ifstream& ifile);     void write(ofstream& ofile);     bool exists(string target);     bool stdexists(string target); friend ofstream& operator<<(ofstream& os, arraystorage& sa); friend ifstream& operator>>(ifstream& is, arraystorage& sa); };  #endif 

linkedliststorage.h

#ifndef lao #define lao  #include <fstream> #include <string> #include <iostream> #include <algorithm>  using namespace std;  class linkedliststorage { private:     void addnode(string line);     void sort();     typedef struct node; public:     node *root;      int size;      void read(ifstream& ifile);     void write(ofstream& ofile);     bool exists(string target);  friend ofstream& operator<<(ofstream& os,linkedliststorage& lls); friend ifstream& operator>>(ifstream& is, linkedliststorage& lls);  };  #endif 

main.ccp

#include <fstream> #include <iostream> using namespace std;  // ***************************** // need create these classes // ***************************** #include "arraystorage.h" #include "linkedliststorage.h"   int main(int argc, char **argv) { string find = "pixel";  // ###################################################### // #################### arraystorage #################### // ######################################################  // *********************************** //        sort read & exists // *********************************** ifstream fin1("acw2_data.txt"); ofstream out1("1-in-sortedread.txt");  if(!fin1.is_open())  {     cout << "fail" << endl;     return 1; }  arraystorage arraystorage1;  // read in values data structure arraystorage1.read(fin1);  // output values in data structure file arraystorage1.write(out1);  fin1.close(); out1.close();  // find item in data structure using own search method if(arraystorage1.exists(find)) {     cout << find.c_str() << " found exists()" << endl; } else {     cout << find.c_str() << " not found exists()" << endl; }     // find item in data structure using std::count method if(arraystorage1.stdexists(find)) {     cout << find.c_str() << " found stdexists()" << endl; } else {     cout << find.c_str() << " not found stdexists()" << endl; }       // ********************************* // sort read & copy constructor // ********************************* ifstream fin2("acw2_data.txt"); ofstream out2("2-out-copyconstructor.txt");  if(!fin2.is_open())  {     cout << "fail" << endl;     return 1; }  arraystorage arraystorage2;  // read in values data structure arraystorage2.read(fin2);  arraystorage arraystorage3 = arraystorage2;  // output values in data structure file arraystorage3.write(out2);  fin2.close(); out2.close();    // ************************************* // >> read & << write // ************************************* ifstream fin3("acw2_data.txt"); ofstream out3("3-in-operatorread.txt"); ofstream out4("4-out-operatorwrite.txt");  if(!fin3.is_open())  {     cout << "fail" << endl;     return 1; }  arraystorage arraystorage4;  fin3 >> arraystorage4; arraystorage4.write(out3);  out4 << arraystorage4;  fin3.close(); out3.close(); out4.close();    // ########################################################### // #################### linkedliststorage #################### // ###########################################################  // *********************************** //        sort read & exists // *********************************** ifstream fin4("acw2_data.txt"); ofstream out5("5-in-sortedread.txt");  if(!fin4.is_open())  {     cout << "fail" << endl;     return 1; }  linkedliststorage llstorage1;  // read in values data structure llstorage1.read(fin4);  // output values in data structure file llstorage1.write(out5);  fin4.close(); out5.close();  // find item in data structure using own search method if(llstorage1.exists(find)) {     cout << find.c_str() << " found exists()" << endl; } else {     cout << find.c_str() << " not found exists()" << endl; }      // ********************************* // sort read & copy constructor // ********************************* ifstream fin5("acw2_data.txt"); ofstream out6("6-out-copyconstructor.txt");  if(!fin5.is_open())  {     cout << "fail" << endl;     return 1; }  linkedliststorage llstorage2;  // read in values data structure llstorage2.read(fin5);  linkedliststorage llstorage3 = llstorage2;  // output values in data structure file llstorage3.write(out6);  fin5.close(); out6.close();   // ************************************* // >> read & << write // ************************************* ifstream fin6("acw2_data.txt"); ofstream out7("7-in-operatorread.txt"); ofstream out8("8-out-operatorwrite.txt");  if(!fin6.is_open())  {     cout << "fail" << endl;     return 1; }  linkedliststorage llstorage4;  fin6 >> llstorage4; llstorage4.write(out7);  out8 << llstorage4;  fin6.close(); out7.close(); out8.close();  cout << endl << "finished" << endl; int keypress; cin >> keypress; return 0; } 

linkedliststorage.ccp

#include <fstream> #include <string> #include <iostream> #include <algorithm>  using namespace std;  class linkedliststorage { private: //methods  //variables typedef struct node {     string word;// data     node *next; //address of next node }; node *root; //root node int size; //size of datafile     public: //methods void addnode(string line) {     node *temp, *temp2;     temp = new node;      temp->word = line;     temp->next = null;      if(root == null)         root = temp;     else     {         temp2 = root;         while(temp2->next != null)             temp2 = temp2->next;         temp2->next = temp;     } } void sort()//simple bubblesort {     node *temp, *temp2;     temp = new node;     temp2 = new node;      string spare = 0;     for( temp = root; temp!=null;temp = temp->next)     {         if(temp->word > temp2->word)         {             spare = temp->word;             temp->word = temp2->word;             temp2->word = spare;         }     }  } void read(ifstream& ifile) {     size = 0;     string line;     if(ifile.is_open())     {         while(std::getline(ifile, line))             ++size; //figures out size dynamic array     }     root = new node;     root->next = 0;//null     root->word = ""; //no data yet      (int = 0; < size; i++)     {         if(i<3)             ifile.ignore();         getline(ifile,line);         addnode(line);         sort();     }  } void write(ofstream& ofile) {     node *temp;     temp = root;     while (temp!=null)     {         ofile << temp->word << endl;         temp = temp->next;     } } bool exists(string target) //i cant think of single way search singly linked     list faster o(n) {     node *temp;     temp = root;     while (temp!=null)     {         if (temp->word == target)             return true;     }     return false; } //constructor linkedliststorage(); //destructor ~linkedliststorage() {     node *ptr;      (ptr = root; root;ptr = root)     {         root = root->next;         delete ptr;     } }  linkedliststorage(const linkedliststorage &other) :root(null) {     node *cur = other.root;     node *end = null;      while(cur)     {         node* x = new node;         x->word = cur->word;          if(!root)         {             root = x;             end = root;         }         else         {             end->next = x;             end = x;         }          cur = cur->next;     } } friend ofstream& operator<<(ofstream& os,linkedliststorage& lls); friend ifstream& operator>>(ifstream& is, linkedliststorage& lls);  };  ofstream& operator<<(ofstream& os, linkedliststorage& lls) { lls.write(os); return os; }  ifstream& operator>>(ifstream& is, linkedliststorage& lls) { lls.read(is); return is; }  , arraystorage.ccp    #include <fstream> #include <string> #include <iostream> #include <algorithm>  using namespace std;   class arraystorage { //variables private: string* storagearray;      int asize; // array size public: //methods void read(ifstream& ifile) {     asize = 0; //intialise     string line;     if(ifile.is_open())     {         while(std::getline(ifile, line))             ++asize; //figures out size dynamic array     }     string *pnarray = new string[asize];//intialise array     (int = 0; < asize; i++)     {         if(i<3)         {             ifile.ignore();         }         getline(ifile,pnarray[i]); //this should not contain important data due way sorting done         sort(pnarray,pnarray + i); //sorts array     }     storagearray = pnarray; } void write(ofstream& ofile) {     if(ofile.is_open())     {         (int j = 0; j < asize; j++)         {             ofile << storagearray[j] << endl;         }     } } bool exists(string target) {     int lo = 1;     int hi = asize - 1;     int mid = 0;     int comparitor = 0;     while(true)     {         mid =(lo+hi+1)/2; // plus 1 force round    nearest highest integer         if(mid == hi)         {             if(comparitor = target.compare(storagearray[lo]) ==  0)             {                 return true;             }             else if(comparitor = target.compare(storagearray[hi]) ==  0)             {                 return true;             }             else             {             return false;             }         }         comparitor = target.compare(storagearray[mid]);         if(comparitor == 0)             return true;         else if(comparitor > 0)             lo = mid;         else if(comparitor < 0)             hi = mid;                } } bool stdexists(string target) {      int check = count(storagearray,storagearray+(asize-1),target);      if(check >0)          return true;      else          return false; } //copy constructor arraystorage(const arraystorage &other) {     storagearray = new string[other.asize];     asize = other.asize;     memcpy(storagearray,other.storagearray,sizeof(string) * asize); } //constructor arraystorage(); //destructor ~arraystorage() {     delete [] storagearray; } //overload operator const arraystorage &operator=(const arraystorage &other) {     if(this == &other) return *this;     delete[] storagearray;     storagearray = new string[other.asize];     asize = other.asize;     memcpy(storagearray,other.storagearray,sizeof(string) * asize);     return *this;      //friends benefit  } friend ofstream& operator<<(ofstream& os, arraystorage& sa); friend ifstream& operator>>(ifstream& is, arraystorage& sa); };  ofstream& operator<<(ofstream& os, arraystorage& sa) { sa.write(os); return os; }  ifstream& operator>>(ifstream& is, arraystorage& sa) { sa.read(is); return is; } 

sorry massive wall of text, if of isn't needed please let me know , i'll remove it!

your source files redefining each class; shouldn't that. instead, should include header defines class, , define each function declared in class. example:

// arraystorage.cpp #include "arraystorage.h"  bool arraystorage::exists(string target) {     // function body here } 

Comments