C++ - Linker-Fehler ("Linker command failed with exit code 1")
Arbeite ich an einem Projekt und bekomme immer einen linker error, obwohl es im wesentlichen keinen ausführbaren code so weit. Die Fehlermeldung ist unten, und von dem, was ich sammeln, es hat zu tun mit der überladene Zuweisungsoperator, das habe ich noch nicht definiert.
Kann ich aufwendige weitere über private Nachrichten, oder wenn Sie möchten, finden Sie den code. Dies ist aufgrund meiner Schule, dem akademischen Integrität Politik, und ich möchte nicht ausgeschlossen werden!
Vielen Dank im Voraus!
Aufrufen: MacOS-X C++ Linker
g++ -o "Projektname" ./Klasse.o -. /ProjectName.o
Undefined Symbole für die Architektur x86_64:
"Class::operator=(Klasse const&)", referenziert von:
Class::Class(Class const&) in Class.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use-v zu sehen invocation)
machen: *** [ProjectName] Fehler 1
** UPDATE **
Wenn du unter "Klasse" eine Klasse name überall, dass bedeutet, ich habe vergessen es zu ändern zurück zu den echten Klassennamen, die ShirtOrder.
Hier ist der code meiner main cpp Datei:
#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)
{
}
meine ShirtOrder.h-Datei:
#ifndef SHIRTORDER_H_
#define SHIRTORDER_H_
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
class ShirtOrder
{
friend ostream& operator<<(ostream &os, const ShirtOrder &rhsObj);
private:
//the data members below are required (you may change identifiers)
//there is no need for additional data members
int orderYear, orderMonth, orderDay;
char printMethod; //'s', 'i', or 'e'
string message;
int mediums; //number of medium shirts ordered
int larges; //number of large shirts ordered
int xls; //number of XL shirts ordered
string shirtColor;
string inkColor;
string orderID;
string region;
string nameAndEmail;
ShirtOrder* next; //new for P5
public:
ShirtOrder(); //default constructor
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 = NULL);
ShirtOrder(const ShirtOrder &otherObj);
~ShirtOrder(); //destructor //New for P5 (may not be in-line)
ShirtOrder* getNext() const {return next;} //New for P5 (may be in-line)
void setNext(ShirtOrder* soPtr) {next = soPtr;} //New for P5 (may be in-line)
ShirtOrder operator=(const ShirtOrder &rhsObj); //New for P5 (may not be in-line)
double getBlankCost() const;
double getPrintingCost() const;
double getTotalCost() const;
int getLetterCount() const;
char getPrintMethod() const {return printMethod;}
int getOrderYear() const {return orderYear;}
int getOrderMonth() const {return orderMonth;}
int getOrderDay() const {return orderDay;}
int getMediums() const {return mediums;}
int getLarges() const {return larges;}
int getXls() const{return xls;}
string getShirtColor() const {return shirtColor;}
string getInkColor() const {return inkColor;}
string getOrderID() const {return orderID;}
string getRegion() const {return region;}
string getNameAndEmail() const {return nameAndEmail;}
string getMessage() const {return message;}
void setOrderYear (int orderYear) {this->orderYear = orderYear;}
void setOrderMonth (int orderMonth) {this->orderMonth = orderMonth;}
void setOrderDay (int orderDay) {this->orderDay = orderDay;}
void setPrintMethod (char printMethod) {this->printMethod = printMethod;}
void setMessage (string message) {this->message = message; }
void setMediums (int mediums) {this->mediums = mediums;}
void setLarges (int larges) {this->larges = larges;}
void setXls (int xls) {this->xls = xls;}
void setShirtColor (string shirtColor) {this->shirtColor = shirtColor;}
void setInkColor (string inkColor) {this->inkColor = inkColor;}
void setOrderID (string orderID) {this->orderID = orderID;}
void setRegion (string region) {this->region = region;}
void setNameAndEmail (string nameAndEmail) {this->nameAndEmail = nameAndEmail;}
}; //end declaration of class ShirtOrder
/******************************************************************************************
*********** MEMBER FUNCTION IMPLEMENTATIONS -- MEMBER FUNCTION IMPLEMENTATIONS ***********
******************************************************************************************/
#endif /* SHIRTORDER_H_ */
meine ShirtOrder.cpp Datei:
#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;
}
- zeig uns code, der Sie
Class
?.. - Ich kann nicht... nicht in einem öffentlichen forum zumindest. Es wäre zu einfach für meinen professor zu finden, diese Frage.
- Du hast mein upvote für Ihre ultra Ehrlichkeit 😀
Du musst angemeldet sein, um einen Kommentar abzugeben.
Linker sagt Ihnen, dass
Class::Class(Class const&)
fehlt Ihr Class.cppMüssen Sie entweder entfernen Sie die Erklärung von Ihrer Klasse.h oder add-Implementierung in Ihrem Class.cpp.
Den Fehler, dass Sie ursprünglich berichtet nicht verlassen übereinstimmung mit dem code. Anyways, das sind die Fragen, die Sie haben:
ShirtOrder operator=(const ShirtOrder &rhsObj)
(sollteShirtOrder&
)*this
;ShirtOrder& ShirtOrder::operator=(const ShirtOrder &rhsObj)
, während es diese in .cpp-Datei:ShirtOrder& ShirtOrder::operator=(const ShirtOrder &rhsObj)
ShirtOrder::ShirtOrder(const ShirtOrder &otherObj)
hat nicht die korrekte Umsetzung. es zu vergeben hat, alle diese Werte zuthis->
stattobject.