c++ - I get this error when compiling: error LNK2019: I get them for two defined functions in main -


it has 2 functions in main. getinput , execfunc. defined in class bibliotek. searched this. can forward declaration? error message is:

1>------ rebuild started: project: ou4sec, configuration: debug win32 ------ 1>  ou4sec.cpp 1>  bibliotek.cpp 1>  generating code... 1>ou4sec.obj : error lnk2019: unresolved external symbol "void __cdecl execfunc(class std::vector<class lendobj *,class std::allocator<class lendobj *> > &,char &,int &)" (?execfunc@@yaxaav?$vector@pavlendobj@@v?$allocator@pavlendobj@@@std@@@std) referenced in function _main 1>ou4sec.obj : error lnk2019: unresolved external symbol "char __cdecl getinput(void)" (?getinput@@yadxz) referenced in function _main 1>msvcrtd.lib(crtexew.obj) : error lnk2019: unresolved external symbol _winmain@16 referenced in function ___tmaincrtstartup 1>c:\users\jonas\documents\visual studio 2010\projects\ou4sec\debug\ou4sec.exe : fatal error lnk1120: 3 unresolved externals ========== rebuild all: 0 succeeded, 1 failed, 0 skipped ========== 

file(main) ou4sec.cpp:

#include "bok.h" #include "cd.h" #include "tidskrift.h" #include "fack.h" #include "nonfack.h" #include "lendobj.h" #include <iostream> #include <fstream> using namespace std; #include <string> #include <cstdio> #include <vector> #include <cstdlib>   char getinput(); void execfunc(vector <lendobj*> &bib,char &c, int &antal); int main() {   char c;   int antal = 0;   vector <lendobj*> biblio;     fstream inf;     inf.open("biblio.txt");     std::string titel;     std::string forf;     int id;     int cnr;     std::string vol;     std::string art;     std::string typ;     string tid;      // if couldn't open input file stream reading     if(inf.is_open())     {            while (inf.good())     {         // read stuff file string , print         std::string strinput;         std::string typ;         int = 0;         while(getline(inf, strinput))             {         if(strinput == "fiction")         {             typ = strinput;             getline(inf, strinput);             forf = strinput;             getline(inf, strinput);             titel = strinput;             getline(inf, strinput);             id = atoi (strinput.c_str());             getline(inf, strinput);             cnr = atoi (strinput.c_str());             biblio.push_back(new nonfack(typ,id, titel, cnr, forf));             = +1;         }         if(strinput == "nonfiction")         {             typ = strinput;             getline(inf, strinput);             forf = strinput;             getline(inf, strinput);             titel = strinput;             getline(inf, strinput);             id = atoi (strinput.c_str());             getline(inf, strinput);             cnr = atoi (strinput.c_str());             biblio.push_back(new fack(typ,id, titel, cnr, forf));             = +1;         }         if(strinput == "journal")         {             typ = strinput;             getline(inf, strinput);             titel = strinput;             getline(inf, strinput);             vol = strinput;             getline(inf, strinput);             id = atoi (strinput.c_str());             getline(inf, strinput);             cnr = atoi (strinput.c_str());             biblio.push_back(new tidskrift(typ,id, titel, cnr, vol));             = +1;         }         if(strinput == "cd")         {             typ = strinput;             getline(inf, strinput);             art = strinput;             getline(inf, strinput);             titel = strinput;             getline(inf, strinput);             tid = strinput;             getline(inf, strinput);             id = atoi (strinput.c_str());             getline(inf, strinput);             cnr = atoi (strinput.c_str());             biblio.push_back(new cd(typ,id, titel,cnr, art, tid));             = +1;         }         }         antal = i;         inf.close();     }      }     else cout << "unable open file"<<endl;    cout << "antal : " << antal << endl;   cout <<"choose 1 of x/c/f/n/j/h(help)/s/b/r/q: "<< endl;   while(1)   {       c = getinput();       if(c=='q')           break;       execfunc(biblio, c, antal);   }   remove("biblio.txt");   for(int = 0;i < antal;i++)   {       biblio[i]->quit();   }   return 0; } 

file "bibliotek.h":

#ifndef bibliotek_h #define bibliotek_h #include "lendobj.h" #include <vector>  class bibliotek { public:     bibliotek();     static void help();     static char getinput();     static void insert(vector <lendobj*> & bib,char &type, int &antal);     static void searchinit(vector <lendobj*> & bib, int &antal);     static void removeinit(vector <lendobj*> & bib, int &antal);     static void borrowinit(vector <lendobj*> & bib, int &antal);     static void givebackinit(vector <lendobj*> & bib, int &antal);     void execfunc(vector <lendobj*> &bib,char &c, int &antal);     ~bibliotek(); }; #endif 

file "bibliotek.cpp":

#include "bibliotek.h" #include "bok.h" #include "cd.h" #include "tidskrift.h" #include "nonfack.h" #include "fack.h" #include "lendobj.h" #include <cstdio> #include <vector> #include <fstream> #include <istream> #include <string> #include <iostream> using namespace std;  bibliotek::bibliotek(void) { } bibliotek::~bibliotek(void) { } void bibliotek::help() {     cout << " c - insert new cd" << endl;     cout << " f - insert new fiction book" << endl;     cout << " n - insert new non-fiction book"<< endl;     cout << " j - insert new journal" << endl;     cout << " x - remove object library" << endl;     cout << " h - show text" << endl;     cout << " s - search" << endl;     cout << " b - borrow object" << endl;     cout << " r - return object" << endl;     cout << " q - quit program" << endl;  }  char bibliotek::getinput() {     char c;     while(c = getchar(),c!='c'&&c!='f'&&c!='n'&&c!='j'&& c!='x'&&         c!='h'&&c!='s'&&c!='b'&&c!='r'&&c!='q')     {         cout <<"choose 1 of x/c/f/n/j/h(help)/s/b/r/q"<<endl;     }     return c; }  void bibliotek::insert(vector <lendobj*> &bib,char &type, int &antal) {     ostringstream os;     string artist;     string titel;     string speltid;     int lendid;     int cnr;     string author;     string volym;     cin.clear();     cin.sync();     if(type == 'c')     {         cout << "enter artist name: ";         getline(cin,artist,'\n');         cout << "enter title: ";         getline(cin,titel);         cout << "enter playtime: ";         getline(cin,speltid);         lendid = bib[antal-1]->getid()+1;         cnr = 0;         bib.push_back(new cd("cd",lendid, titel, cnr, artist, speltid));         antal = antal + 1;     }     if(type == 'f')     {         cout << "enter name of author : ";         getline(cin,author);         cout << "enter title: ";         getline(cin,titel);         lendid = bib[antal-1]->getid()+1;         cnr = 0;         bib.push_back(new nonfack("fiction",lendid, titel, cnr, author));         antal = antal + 1;     }     if(type == 'n')     {         cout << "enter name of author : ";         getline(cin,author);         cout << "enter title: ";         getline(cin,titel);         lendid = bib[antal-1]->getid()+1;         cnr = 0;         bib.push_back(new fack("nonfiction",lendid, titel, cnr, author));         antal = antal + 1;     }     if(type == 'j')     {         cout << "enter name of journal : ";         getline(cin,titel);         cout << "enter volume: ";         getline(cin,volym);         lendid = bib[antal-1]->getid()+1;         cnr = 0;         bib.push_back( new tidskrift("journal",lendid, titel, cnr, volym));         antal = antal + 1;     }     cout <<"choose 1 of x/c/f/n/j/h(help)/s/b/r/q"<<endl; } void bibliotek::searchinit(vector <lendobj*> & bib, int &antal) {     char stype;     string sterm;     string result;     cin.clear();     cin.sync();     cout << "search title (t) or author/artist (a)?" << endl;     cin >> stype;     cout << "enter search term: ";     cin >> sterm;     vector <lendobj*>::const_iterator it;     for(it = bib.begin(); != bib.end();it++)     {         if(stype == 't')         result = (*it)->searcht(sterm);         if(!result.empty())         {         (*it)->printres(result);         result = "";         }         else if(stype == 'a')         result = (*it)->searcha(sterm);         if(!result.empty())         {         (*it)->printres(result);         result = "";         }     }   } void bibliotek::removeinit(vector <lendobj*>& bib, int &antal) {     int id;     int index = 0;     int found= 0;     cout << "antal: " << antal << endl;     cout << "enter id of object remove: " ;     cin >> id;     vector <lendobj*>::iterator it;     for(it = bib.begin(); != bib.end();it++)     {     if((*it)->getid() == id)     {         delete *it;         = bib.erase(it);         found = 1;         break;     }     }      antal = antal-1;     if (found == 0)         cout<<"id not exist!"<<endl; } void bibliotek::borrowinit(vector <lendobj*> & bib, int &antal) {     int id;     int cnr;     int found = 0;     cin.clear();     cin.sync();     cout << "enter lend id: ";     cin >> id;     cout<<id<<endl;     cout << "enter customernumber: ";     cin >> cnr;     cout<<cnr<<endl;     for(int = 0; i< antal; i++)     {         bib[i]->borrow(cnr, id,found);     }     if(found == 0)         cout<<"id not exist!"<<endl; } void bibliotek::givebackinit(vector <lendobj*> & bib, int &antal) {     int id;     int found = 0;     cout << "enter lend id: ";     cin >> id;     for(int = 0; i< antal; i++)     {         bib[i]->giveback(id,found);     }     if(found == 0)         cout<<"id not exist!"<<endl; } void bibliotek::execfunc(vector <lendobj*>& bib,char &c, int &antal ) {      switch(c)     {     case 'c': insert(bib,c,antal); break;     case 'f': insert(bib,c,antal); break;     case 'n': insert(bib,c,antal); break;     case 'j': insert(bib,c,antal); break;     case 'x': removeinit(bib,antal); break;     case 'h': help(); break;     case 's': searchinit(bib,antal); break;     case 'b': borrowinit(bib,antal); break;     case 'r': givebackinit(bib,antal); break;      default:         cout << "not valid character" << endl;     } } 

the problem main forward-declares these 2 functions

char getinput(); void execfunc(vector <lendobj*> &bib,char &c, int &antal); 

without providing implementation them. however, looks trying reference existing functions of bibliotek class:

char bibliotek::getinput(); void bibliotek::insert(vector <lendobj*> &bib,char &type, int &antal); 

if want call member functions of bibliotek, need call them using member syntax if function non-static (i.e. needs reference non-static member variables), or use bibliotek::getinput() if corresponding function static. in either case, need remove forward declarations of functions inserted in main, , replace them inclusion of header declares bibliotek class.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -