由于从结构头创建矢量数组而导致错误LNK2019?

时间:2012-04-29 05:01:58

标签: c++ vector error-handling lnk2001

我正在尝试从输入文件创建数组向量,然后将向量加载到main中。我也试图在整个程序中使用相同的向量。然而,当我编译时,我得到了一堆错误LNK2019。我想我已经知道这是怎么回事,但我不确定为什么。有人可以帮忙解释一下吗?谢谢!

     #include <iostream>
     #include <string>
     #include <vector>
     #include "Database.h"
     #include "Registration.h"
     #include "Competition.h"
     #include "Events.h"
     #include "CompPop.h"
     #include "PushRegistration.h"
     using namespace std;

     void main()
     {
         vector<Competition> myVector = CompPop();
         vector<Registration> myRegistration = PushRegistration();
         Database home(myVector, myRegistration);

         home.Menu();

         system("pause");
     }

似乎发生在: 矢量&lt;比赛&gt; myVector 2.矢量&lt;登记&gt; myRegistration

这些是我得到的错误消息

错误LNK2001:未解析的外部符号“public:__thiscall Registration ::〜Registration(void)”(?? 1Registration @@ QAE @ XZ)

错误LNK2001:未解析的外部符号“public:__ thiscall Database :: ~Database(void)”(?? 1Database @@ QAE @ XZ)

我的Compop标题,从文件中读取并将内容存储到竞争向量中(类似于我的PushRegistration标题)

      #pragma once

     #include <fstream>
     #include <sstream>
     #include <iostream>
     #include <string>
     #include <vector>
     #include "LogIn.h"
     #include "Registration.h"
     #include "Events.h"
     #include "Competition.h"
     using namespace std;

     vector<Competition> CompPop()
     {
         ifstream myfile("PSU Results.txt");

         string line, tcomp, tleader, tfollower, tevents, tplacement;
         vector<Competition> info;
         if(myfile.is_open())
         {
             int i = 0; // finds first line
             int n = 0; // current vector index
             int space;
             while(!myfile.eof())
             {
                 getline(myfile,line);

                 if(line[i] == '*')
                 {
                     space = line.find_first_of(" ");

                     tleader = line.substr(0+1, space);
                     tfollower = line.substr(space + 1, line.size());

                 }
                 else
                 {
                     if(line[i] == '-')
                     {
                         tcomp = line.substr(1, line.size());
                         Competition temp(tcomp, tleader, tfollower);
                         info[n] = temp;
                     }
                     else
                     {
                         if(!line.empty())
                         {
                             line = line;

                             space = line.find_first_of(",");
                             tevents = line.substr(0, space);
                             tplacement = line.substr(space + 2, line.size());
                             info[n].pushEvents(tevents,tplacement);
                         }
                         if(line.empty())
                         {
                             n++;
                         }
                     }
                 }
             }
         }
         else
         {
             cout << "Unable to open file";
        }

         myfile.close();

         return info;
     }

我的竞赛标题(与我的注册标题类似):

     #pragma once

     #include <fstream>
     #include <sstream>
     #include <iostream>
     #include <string>
     #include <vector>
     #include "LogIn.h"
     #include "Registration.h"
     #include "Events.h"
     using namespace std;

     struct Competition
     {
     public:

        Competition(string compName, string lead, string follow)
         {
            Name = compName;
            Leader = lead;
             Follower = follow;
         }

         void pushEvents(string name, string place)
         {
             Events one(name, place);
             Eventrandom.push_back(one);
         }

         string GetName()
         {
            return Name;

         }

         string GetLeader()
         {
            return Leader;
         }

         string GetFollow()
         {
            return Follower;
         }

         string GetEvent()
         {
            return Event;
         }

         string GetScore()
         {
            return Score;
         }

         void Print()
         {
             cout << "Leader: " << Leader << endl;
             cout << "Follower: " << Follower << endl;
            cout << "Competition: " << Name << endl;
             cout << "Events and Placement: " << endl;

             for(vector<Events>::iterator pos = Eventrandom.begin(); pos !=                      Eventrandom.end(); ++pos)
             {
                 cout << pos->eventName << " " << pos->Placement << endl;
             }

             cout << endl;
         }

         ~Competition();

     private:
        string Name, Leader, Follower, Event, Score;

         vector<Events> Eventrandom;
     };

我的注册标题:

     #pragma once

     #include <iostream>
     #include <string>
     #include <fstream>
     using namespace std;

     #define MAX_LENGTH 7 
     #define MAX_DANCES 9

     class Registration
     {
     public:

         Registration();

         Registration(string confirmationCode, string follower, string leader, string comp, string level, string dance);

         void FirstTime();

         void infoFollower();

         void infoLeader();

         string gen_random(const int len);

         string Levels();

         string Dances();

         void Print();

              void print2Confirmation();

         ~Registration();

     private:

         string CCode, Follower, Leader, Name;
         string Level, Dance;

     };

1 个答案:

答案 0 :(得分:1)

错误信息非常清楚。

  

未解析的外部符号“public:__ thishisall   登记::〜登记(无效)“

Registration::~Registration(void)Registration类的析构函数。你定义了一个吗?