C++ C++;链接器错误(“链接器命令失败,退出代码为1”)
我正在做一个项目,并且不断得到一个链接器错误,即使到目前为止基本上还没有可执行代码。下面是错误消息,从我收集的信息来看,它与重载赋值运算符有关,我还没有定义它 我可以通过私人消息进一步阐述,或者如果您想查看代码的话。这是由于我学校的学术诚信政策,我不希望被开除 提前谢谢C++ C++;链接器错误(“链接器命令失败,退出代码为1”),c++,eclipse,compiler-errors,linker,linker-errors,C++,Eclipse,Compiler Errors,Linker,Linker Errors,我正在做一个项目,并且不断得到一个链接器错误,即使到目前为止基本上还没有可执行代码。下面是错误消息,从我收集的信息来看,它与重载赋值运算符有关,我还没有定义它 我可以通过私人消息进一步阐述,或者如果您想查看代码的话。这是由于我学校的学术诚信政策,我不希望被开除 提前谢谢 调用:MaOS X C++链接器< /P> g++-o“ProjectName”。/Class.o./ProjectName.o 架构x86_64的未定义符号: “Class::operator=(Class const&)”
调用:MaOS X C++链接器< /P> g++-o“ProjectName”。/Class.o./ProjectName.o
架构x86_64的未定义符号: “Class::operator=(Class const&)”,引用自:
Class::Class(Class const&) in Class.o
ld:找不到架构x86_64的符号
叮当声:错误:链接器命令失败,退出代码为1(使用-v查看调用)
make:**[ProjectName]错误1
**更新**
如果你在任何地方看到“Class”作为类名,那意味着我忘了把它改回真正的类名,也就是ShirtOrder
以下是我的主cpp文件中的代码:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include "ShirtOrder.h"
using namespace std;
/*********************************************************************************************************************
***************** FUNCTION PROTOTYPES -- FUNCTION PROTOTYPES -- FUNCTION PROTOTYPES -- FUNCTION PROTOTYPES **********
*********************************************************************************************************************/
bool uploadFile(string fName, unsigned long &count, ShirtOrder* &head);
void clearLL(unsigned long &count, ShirtOrder* &head);
void summaryByMethod(unsigned long count, ShirtOrder* head);
void summaryByRegion(unsigned long count, ShirtOrder* head);
/*********************************************************************************************************************
***************** MAIN FUNCTION -- MAIN FUNCTION -- MAIN FUNCTION -- MAIN FUNCTION -- MAIN FUNCTION *****************
*********************************************************************************************************************/
int main(int argc, char* argv[])
{
if (argc < 2) // if only command line argument is program name
{
cout << "No file name entered." << endl;
}
else
{
ShirtOrder object;
cout << "Test run" << endl;
}
return 0;
}
/**********************************************************************************************************
************ FUNCTION IMPLEMENTATIONS -- FUNCTION IMPLEMENTATIONS -- FUNCTION IMPLEMENTATIONS ************
**********************************************************************************************************/
bool uploadFile(string fName, unsigned long &count, ShirtOrder* &head)
{
return true;
}
void clearLL(unsigned long &count, ShirtOrder* &head)
{
}
void summaryByMethod(unsigned long count, ShirtOrder* head)
{
}
void summaryByRegion(unsigned long count, ShirtOrder* head)
{
}
#包括
#包括
#包括
#包括
#包括
#包括“ShirtOrder.h”
使用名称空间std;
/*********************************************************************************************************************
*****************功能原型——功能原型——功能原型——功能原型**********
*********************************************************************************************************************/
bool上传文件(字符串fName、无符号long和count、ShirtOrder*&head);
void clearLL(未签字的长款和计数、衬衫和头部);
void summaryByMethod(无符号长计数,ShirtOrder*head);
无效汇总按区域(无符号长计数,ShirtOrder*头);
/*********************************************************************************************************************
*****************主功能——主功能——主功能——主功能——主功能——主功能*****************
*********************************************************************************************************************/
int main(int argc,char*argv[])
{
if(argc<2)//如果只有命令行参数是程序名
{
cout mediums=介质;}
void setLarges(int larges){this->larges=larges;}
void setXls(intxls){this->xls=xls;}
void setShirtColor(字符串shirtColor){this->shirtColor=shirtColor;}
void setInkColor(字符串inkColor){this->inkColor=inkColor;}
void setOrderID(字符串orderID){this->orderID=orderID;}
void setRegion(字符串区域){this->region=region;}
void setNameAndEmail(字符串nameAndEmail){this->nameAndEmail=nameAndEmail;}
}; // 类ShirtOrder的结束声明
/******************************************************************************************
***********成员函数实现——成员函数实现***********
******************************************************************************************/
#endif/*SHIRTORDER_H_*/
我的ShirtOrder.cpp文件:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include "ShirtOrder.h"
using namespace std;
/*********************************************************************************************************************
***************** FUNCTION PROTOTYPES -- FUNCTION PROTOTYPES -- FUNCTION PROTOTYPES -- FUNCTION PROTOTYPES **********
*********************************************************************************************************************/
bool uploadFile(string fName, unsigned long &count, ShirtOrder* &head);
void clearLL(unsigned long &count, ShirtOrder* &head);
void summaryByMethod(unsigned long count, ShirtOrder* head);
void summaryByRegion(unsigned long count, ShirtOrder* head);
/*********************************************************************************************************************
***************** MAIN FUNCTION -- MAIN FUNCTION -- MAIN FUNCTION -- MAIN FUNCTION -- MAIN FUNCTION *****************
*********************************************************************************************************************/
int main(int argc, char* argv[])
{
if (argc < 2) // if only command line argument is program name
{
cout << "No file name entered." << endl;
}
else
{
ShirtOrder object;
cout << "Test run" << endl;
}
return 0;
}
/**********************************************************************************************************
************ FUNCTION IMPLEMENTATIONS -- FUNCTION IMPLEMENTATIONS -- FUNCTION IMPLEMENTATIONS ************
**********************************************************************************************************/
bool uploadFile(string fName, unsigned long &count, ShirtOrder* &head)
{
return true;
}
void clearLL(unsigned long &count, ShirtOrder* &head)
{
}
void summaryByMethod(unsigned long count, ShirtOrder* head)
{
}
void summaryByRegion(unsigned long count, ShirtOrder* head)
{
}
#include "ShirtOrder.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
/******************************************************************************************
*********** MEMBER FUNCTION IMPLEMENTATIONS -- MEMBER FUNCTION IMPLEMENTATIONS ***********
******************************************************************************************/
// Default Constructor
ShirtOrder::ShirtOrder()
{
orderYear = 0;
orderMonth = 0;
orderDay = 0;
printMethod = 'x'; // 's', 'i', or 'e'
message = "";
mediums = 0; // number of medium shirts ordered
larges = 0; // number of large shirts ordered
xls = 0; // number of XL shirts ordered
shirtColor = "";
inkColor = "";
orderID = "";
region = "";
nameAndEmail = "";
next = NULL;
cout << "Default constructor has run" << endl;
}
// Other Constructor
ShirtOrder::ShirtOrder(int orderYear, int orderMonth, int orderDay,
char printMethod, string message, int mediums, int larges, int xls,
string shirtColor, string inkColor, string orderID,
string region, string nameAndEmail, ShirtOrder *soPtr)
{
this-> orderYear = orderYear;
this->orderMonth = orderMonth;
this->orderDay = orderDay;
this->printMethod = printMethod; // 's', 'i', or 'e'
this->message = message;
this->mediums = mediums; // number of medium shirts ordered
this->larges = larges; // number of large shirts ordered
this->xls = xls; // number of XL shirts ordered
this->shirtColor = shirtColor;
this->inkColor = inkColor;
this->orderID = orderID;
this->region = region;
this->nameAndEmail = nameAndEmail;
next = NULL;
cout << "Constructor Numero Dos has run" << endl;
}
// Other, other constructor
ShirtOrder::ShirtOrder(const ShirtOrder &otherObj)
{
ShirtOrder object;
object = otherObj;
object.orderYear = otherObj.orderYear;
object.orderMonth = otherObj.orderMonth;
object.orderDay = otherObj.orderDay;
object.printMethod = otherObj.printMethod;
object.message = otherObj.message;
object.mediums = otherObj.mediums;
object.larges = otherObj.larges;
object.xls = otherObj.xls;
object.shirtColor = otherObj.shirtColor;
object.inkColor = otherObj.inkColor;
object.orderID = otherObj.orderID;
object.region = otherObj.region;
object.nameAndEmail = otherObj.nameAndEmail;
object.next = otherObj.next;
cout << "Constructor Numero Tres has run" << endl;
}
// DESTRUCTOR
ShirtOrder::~ShirtOrder()
{
cout << "Destructor has run" << endl;
}
ShirtOrder operator=(const ShirtOrder &rhsObj)
{
}
// COME BACK TO REMOVE WHITESPACE
int ShirtOrder::getLetterCount() const
{
string tempMessage = getMessage();
int pos1 = tempMessage.find("\"") + 1; // find first occurrence of a double quotation mark and assign position +1 value to pos1
int pos2 = tempMessage.rfind("\"") - 1; // find last occurrence of a double quotation mark and assign position -1 value to pos2
tempMessage = tempMessage.substr(pos1, (pos2 - pos1)); // sets variable tempMessage to string between quotation marks
return tempMessage.length();
}
double ShirtOrder::getBlankCost() const
{
return 0.0;
}
double ShirtOrder::getPrintingCost() const
{
return 0.0;
}
double ShirtOrder::getTotalCost() const
{
return 0.0;
}
#包括“ShirtOrder.h”
#包括
#包括
#包括
#包括
使用名称空间std;
/******************************************************************************************
***********成员函数实现——成员函数实现***********
******************************************************************************************/
//默认构造函数
ShirtOrder::ShirtOrder()
{
orderYear=0;
orderMonth=0;
orderDay=0;
printMethod='x';//'s'、'i'或'e'
message=“”;
介质=0;//订购的介质衬衫数量
larges=0;//订购的大衬衫数量
xls=0;//订购的XL衬衫数量
衬衫颜色=”;
inkColor=“”;
orderID=“”;
地区=”;
nameAndEmail=“”;
next=NULL;
cout orderMonth=orderMonth;
此->订单日=订单日;
this->printMethod=printMethod;//'s'、'i'或'e'
此->消息=消息;
此->介质=介质;//订购的中等衬衫数量
this->larges=larges;//订购的大衬衫数量
此->xls=xls;//订购的XL衬衫数量
此->衬衫颜色=衬衫颜色;
此->inkColor=inkColor;
此->订单ID=订单ID;
该->区域=区域;
此->nameAndEmail=nameAndEmail;
next=NULL;
cout链接器告诉您Class.cpp中缺少Class::Class(Class const&)
您需要从Class.h中删除其声明,或者在Class.cpp中添加实现
您最初报告的错误与代码不匹配。总之,您存在以下问题:
- 赋值运算符返回错误:
ShirtOrder运算符=(const ShirtOrder&rhsObj)
(应为ShirtOrder&
)
- 运算符=的实现为空,您应该分配成员,然后返回
*this
- 操作符=定义为
ShirtOrder&ShirtOrder::operator=(const ShirtOrder&rhsObj)
,而它必须是.cpp文件中的操作符:ShirtOrder&ShirtOrder::operator=(const ShirtOrder&rhsObj)
- 您的复制构造函数
ShirtOrder::ShirtOrder(const ShirtOrder&otherObj)
没有正确的实现。它必须将所有这些值分配给this->
而不是对象。
向我们展示你的代码类
?…我不能…至少不能在公共论坛上。我的教授很容易找到这个问题。@GeniunExtDoor你的超诚实得到了我的支持:我现在得到这个错误:../Class.cpp:96:12:错误:重载的“运算符=”必须是二进制运算符(有1个参数)类运算符=(const Class&rhsObj)^@geniunsextdoor将您的类名重命名为其他名称并发布。您可以