gpt4 book ai didi

C++错误error LNK2019 : unresolved external symbol,语法错误?

转载 作者:行者123 更新时间:2023-11-30 03:58:30 28 4
gpt4 key购买 nike

<分区>

这是大学 C++ 作业,所以我还是初学者,但我以前从未见过这个错误。该程序只是简单的制作一个类,制作两个类对象并将类的属性吐出给用户所有属性都必须通过Set Get函数进行检查。如果有人可以解释这个错误并教我如何预防/修复它,将不胜感激,谢谢!

这是完整的错误:错误 1 ​​error LNK2019: 未解析的外部符号“public: __thiscall invoice::invoice(class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator >,int,int)” (? ?0invoice@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0HH@Z) 在函数_main C:\Users\PBirkholtz001\Desktop 中引用\Exam Finals\invoicerExamQuest1\invoicerExamQuest1\Source.obj invoicerExamQuest1

错误 2 error LNK1120: 1 unresolved externals C:\Users\PBirkholtz001\Desktop\Exam Finals\invoicerExamQuest1\Debug\invoicerExamQuest1.exe invoicerExamQuest1

这是我的头文件:

 #ifndef INVOICE_H
#define INVOICE_H

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

class invoice{

private:
// Variables for the class
string partNum;
string desc;
int quant;
int price;

public:
//constructor
invoice(string partNum = "f000", string desc = "HardWare", int quant = 1, int price = 0);

//////////////////get set functions////////////////////////////////
void setpartnum(string a){
partNum = a;
}
string getpartnum(){
return partNum;
}
//////////////////////////////////////////////////
void setdesc(string b){
desc = b;
}
string getdesc(){
return partNum;
}
/////////////////////////////////////////////////
void setquant(int x){
quant = x;
}
int getquant(){
return quant;
}
////////////////////////////////////////////////
void setprice(int y){
quant = y;
}
int getprice(){
return price;
}
/////////////////Total function//////////////////////////////
int invoiceAmount(){
return quant * price;
}
///////////////////////////////////////////////
};
#endif

这是我的源文件:

#include <iostream>
#include "Header.h"
using namespace std;

int main(){

invoice invoice1;

invoice1.setpartnum("SD001");
invoice1.setdesc("PNY 100Gb Solid State Drive");
invoice1.setprice(120);
invoice1.setquant(1);

cout << "you have ordered: " << invoice1.getquant() << " " << invoice1.getpartnum() << endl;
cout << " which will cost: $" << invoice1.getprice() << " your total comes to: $" << invoice1.invoiceAmount() << endl;

system("pause");
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com