错误LNK 2019 Visual Studio 2013

时间:2016-10-13 17:54:02

标签: c++ visual-studio-2013 lnk2019

我正在构建一个程序,它从输入文件中读取状态(字符串)和税率(浮点数),并将其存储到名为TaxBill的类的对象向量中。该类有3个数据成员,名为stateName,taxBill和index。每个相应的数据成员还有set()/ get()函数。

现在,我对我的代码没有疑问(它不完整,但我还在努力)。每次我尝试编译它时都会收到此错误。

1>------ Build started: Project: Michael Bagnasco - CSIS 112(2), Fall 2016 - Lab 4, Configuration: Debug Win32 ------
1>Michael Bagnasco - CSIS 112(2), Fall 2016 - Lab 4.obj : error LNK2019: unresolved external symbol "public: __thiscall TaxBill::TaxBill(void)" (??0TaxBill@@QAE@XZ) referenced in function "public: void __thiscall std::allocator<class TaxBill>::construct(class TaxBill *)" (?construct@?$allocator@VTaxBill@@@std@@QAEXPAVTaxBill@@@Z)
1>C:\Users\Bagnastayy\Documents\Visual Studio 2013\Projects\Michael Bagnasco - CSIS 112(2), Fall 2016 - Lab 4\Debug\Michael Bagnasco - CSIS 112(2), Fall 2016 - Lab 4.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我无法弄清楚出了什么问题所以我创建了一个新项目并导入了我的cpp和头文件,我得到了同样的错误。然后我使用不同的.NET框架创建了一个新项目(4.5.1,之前我使用的是4.6.2)。发生了同样的错误然后我尝试使用.NET 4.5.1创建一个项目,并在项目创建菜单中选择“Empty Project”。我得到了同样的错误。

然后我做了一个简单的“Hello World”程序,看看我的编译器是否有问题。程序运行得很好。以下是Debug文件夹中.log的输出。

1>Project "c:\Users\bagnastayy\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1.vcxproj" on node 2 (Build target(s)).
     1>ClCompile:
         C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt Source.cpp
         Source.cpp
       Link:
         C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"c:\users\bagnastayy\documents\visual studio 2013\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"c:\users\bagnastayy\documents\visual studio 2013\Projects\ConsoleApplication1\Debug\ConsoleApplication1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"c:\users\bagnastayy\documents\visual studio 2013\Projects\ConsoleApplication1\Debug\ConsoleApplication1.lib" /MACHINE:X86 Debug\Source.obj
         ConsoleApplication1.vcxproj -> c:\users\bagnastayy\documents\visual studio 2013\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe
     1>Done Building Project "c:\Users\bagnastayy\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1.vcxproj" (Build target(s)).

谁能告诉我发生了什么事或我做错了什么?我的代码如下。

Michael Bagnasco - CSIS 112(2),2016年秋季 - 实验室4.cpp

// Michael Bagnasco
//CSIS 112 – Fall 2016
//Lab 4 - 

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "TaxBill.h"
using namespace std;

const string ID = "Michael Bagnasco - CSIS 112(2), Fall 2016 - Lab 4";


int main()
{
    cout << endl << "Running Lab 4 . . . " << endl;
    cout << ID << endl;
    cout << "              Console Output" << endl << endl << endl;


    //  DEFINITIONS
    bool  noErrors = true;
    char  exit;
    ifstream fin;
    ofstream fout,
        errOut;
    const int SALARY = 100000,
        HOUSE = 267000,
        ANNUAL = 36000;
    vector<TaxBill> States(1);
    string stateName;
    double salesTax,
        propertyTax,
        incomeTax;
    int temp;

    //  ADMINISTRATIVE STUFF
    fin.open("Lab4.dat");
    fout.open(ID + ".out");
    errOut.open(ID + ".err");
    fout << ID << endl;
    fout << "               Main Report" << endl << endl << endl;
    errOut << ID << endl;
    errOut << "         ***  Error Report  ***" << endl << endl << endl;


    //  PROGRAM LOGIC

    //  FIRST READ LOOP
    for (int i = 0; fin >> stateName >> salesTax >> propertyTax >> incomeTax; i++)
    {
        //  NAMING STATES IN VECTOR AND SIZING VECTOR
        States.at(i).setStateName(stateName);
        States.resize(i + 1);

    }
    cout << States.size();
    temp = States.size();
    int taxRates[5][4];

    //  SECOND READ LOOP
    for (int i = 0; fin >> stateName >> salesTax >> propertyTax >> incomeTax; i++)
    {

    }



    //EXIT ROUTINE
    errOut << endl << endl;
    fout << endl << endl;
    cout << endl << endl;

    if (noErrors)
        errOut << "No Errors Were Detected" << endl << endl << endl;

    errOut << "END OF ERROR REPORT";
    fout << "END OF MAIN REPORT";
    cout << "Enter any key to end execution of this program   . . .   ";
    cin >> exit;                                             //to pause program
    return 0;
}

TaxBill.h

// TaxBill Class Interface


#include <iostream>
#include <string>

using namespace std;


#ifndef _TAXBILL_H_
#define _TAXBILL_H_


class TaxBill
{
public:
    TaxBill();
    void setStateName(string);
    void setTaxBill(double);
    void setIndex(int);
    string getStateName();
    double getTaxBill();
    int getIndex();

private:
    string stateName;
    double taxBill;
    int index;
};

#endif 

TaxBill.cpp

#include "TaxBill.h"

void TaxBill::setStateName(string inName)
{
    stateName = inName;
}


void TaxBill::setTaxBill(double inBill)
{
    taxBill = inBill;
}


void TaxBill::setIndex(int inIndex)
{
    index = inIndex;
}


string TaxBill::getStateName()
{
    return stateName;
}


double TaxBill::getTaxBill()
{
    return taxBill;
}


int TaxBill::getIndex()
{
    return index;
}

0 个答案:

没有答案