Reputation: 2181
I tried to use my own destructor instead of the default destructor but I get the following error anyhow. Does anyone know why I'm getting this?
error:
AssignmentRepository.o: In function `ZNSt6vectorI10AssignmentSaIS0_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS0_S2_EERKS0_':
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/bits/vector.tcc:308: undefined reference to `Assignment::~Assignment()'
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/bits/vector.tcc:308: undefined reference to `Assignment::~Assignment()'
AssignmentRepository.o: In function `ZN9__gnu_cxx13new_allocatorI10AssignmentE7destroyEPS1_':
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/ext/new_allocator.h:118: undefined reference to `Assignment::~Assignment()'
AssignmentRepository.o: In function `ZSt8_DestroyI10AssignmentEvPT_':
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/include/c++/bits/stl_construct.h:94: undefined reference to `Assignment::~Assignment()'
collect2: ld returned 1 exit status
Code of the class in .h file:
#ifndef ASSIGNMENTREPOSITORY_H_
#define ASSIGNMENTREPOSITORY_H_
#include "Assignment.h"
#include <vector>
class AssignmentRepository{
private:
vector <Assignment> assignments;
public:
vector <Assignment> getAll();
void save(Assignment);
void editAssignment(Assignment);
int searchById(int);
void printAllAssignments();
int findByName(string name);
Assignment *getAssignment(int i);
~AssignmentRepository();
};
#endif /* ASSIGNMENTREPOSITORY_H_ */
.cpp file of the class:
int AssignmentRepository::searchById(int a){
for(unsigned i=0; i<assignments.size(); i++){
if(a == assignments[i].getID()){
return i;
}
}
return 0;
}
AssignmentRepository::~AssignmentRepository(){
}
Assignment.h class header:
class Assignment {
private:
int id;
int grade;
int dLine;
string descrption;
public:
Assignment(int gr, int dl, string desc):grade(gr),dLine(dl),descrption(desc){};
~Assignment();
void setGrade(int value) {grade = value;}
void setDLine(int value) {dLine = value;}
void setDescription(string value) {descrption = value;}
void setID(int value) {id = value;}
int getID() const{return id;}
int getGrade() const{return grade;}
int getDLine() const{return dLine;}
string getDescription() const{return descrption;}
friend ostream& operator << (ostream& out, const Assignment& assignment)
{
out << assignment.grade << " " << assignment.dLine << " " << assignment.descrption <<endl;
return out;
}
};
#endif /* ASSIGNMENT_H_ */
Upvotes: 0
Views: 229
Reputation: 168616
You have declared the Assignment
destructor, but you have not defined it.
Try replacing this line:
~Assignment();
with this one:
~Assignment() {}
Upvotes: 4