First, I'll go ahead and thank any of you who can help me. Godspeed.
Second, I'll give some small background which may or may not be a part of my problem.
I'm a college student in the entry level C++ course. I've had two semesters of Java and a lot of practice programming. The concepts aren't lost on me, but a lot of the syntax and terms are for C++.
Now, to the problem:
I've spent the past few days working on the first assignment for my course. Essentially it involves creating a list of assignments. Each assignment is an object and each object has two pieces of data; A name, and a due date.
I'm using Dev-C++ 4.9.9.2 and there are 5 files in my project. I've managed to get it to compile without any of the normal issues I run into, typically syntax errors. Now I'm getting the dreaded "[Linker error] undefined reference to 'class::function()' type error.
Specifically, the error Dev-C++ is giving me is
I understand what that error is and I've had it before. Usually it's because I forgot to put a ; at the end of my header file or forgot to include it in my .cpp file. I've been combing through my code for a little over an hour now and I just can't figure this one out. And here we are.[Linker error] undefined reference to `assignment::getDue()'
[Linker error] undefined reference to `assignment::getName()'
[Linker error] undefined reference to `assignment::getDue()'
[Linker error] undefined reference to `assignment::getName()'
[Linker error] undefined reference to `assignment::getDue()'
[Linker error] undefined reference to `assignment::getName()'
[Linker error] undefined reference to `assignment::getName()'
[Linker error] undefined reference to `assignment::getName()'
Id returned 1 exit status
[Build Error] [Assignment1.exe]Error1
Now, for the code!
assignment.h
assignment.cppCode:#ifndef ASSIGNMENT_H #define ASSIGNMENT_H #include <iostream> #include <list> #include <string> using namespace std; class assignment { public: assignment(string name, string due); string getName(); string getDue(); string assName, assDue; }; #endif
assList.hCode:#include "assignment.h" using namespace std; string assName, assDue; assignment::assignment(string name, string due) { assName = name; assDue = due; } string getName() { return assName; } string getDue() { return assDue; }
assList.cppCode:#ifndef ASSLIST_H #define ASSLIST_H #include "assignment.h" #include <iostream> #include <list> #include <string> using namespace std; class assList { public: assList(); //create list void add(assignment ***); //Add a new assignment to the list void remove(string myName); //Remove an assignment from the list void printList(); //Cout the list in the order they were input void find(); //Find the assignment with the earliest due date. list<assignment> myList; }; #endif
main.cppCode:#include "assList.h" #include "assignment.h" #include <list> #include <string> using namespace std; assList::assList() { list<assignment> myList; } void assList::add(assignment ***) { myList.push_front(***); } void assList::find() { list<assignment>::iterator date; date = myList.begin(); assignment temp = *date; string earliest = temp.getDue(); string name = temp.getName(); while(date != myList.end()) { date++; assignment nextTemp = *date; string nextDate = nextTemp.getDue(); string nextName = nextTemp.getName(); if(nextDate < earliest) { earliest = nextDate; name = nextName; } } cout<<name<<" is due the earliest on : "<<earliest; } void assList::printList() { list<assignment>::iterator printiter; printiter = myList.begin(); assignment temp = *printiter; while(printiter != myList.end()) { temp = *printiter; cout<<temp.getName()<<" "<<temp.getDue()<<"\n"; printiter++; } } void assList::remove(string myName) { list<assignment>::iterator front,current, back; front = myList.begin(); current = front; back = myList.end(); back--; bool deleted = false; assignment temp = *current; string currentName = temp.getName(); if(currentName == myName) { myList.erase(current); deleted = true; } else { while(current != myList.end()) { current++; temp = *current; currentName = temp.getName(); if(currentName == myName) { myList.erase(current); deleted = true; } } } if(deleted) cout<<myName<<" was found and deleted."<<"\n"; else cout<<myName<<" was not found!."<<"\n"; }
Again, thank you guys for any help you can give me.Code:#include <iostream> #include <stdlib.h> #include <string> #include <list> #include "assignment.h" #include "assList.h" using namespace std; int main() { assList List; assignment a1("Assignment1", "Feb 20, 2009"); List.add(a1); assignment a2("Assignment2", "Feb 25, 2009"); List.add(a2); assignment a3("Assignment3", "Feb 17, 2009"); List.add(a3); assignment a4("Assignment4", "Feb 21, 2009"); List.add(a4); assignment a5("Assignment5", "Feb 19, 2009"); List.add(a5); List.printList(); system("PAUSE"); List.find(); system("PAUSE"); List.remove("Assignment3"); system("PAUSE"); assignment a6("Assignment6", "Feb 18, 2009"); List.add(a6); List.printList(); system("PAUSE"); List.find(); system("PAUSE"); return 0; }




Reply With Quote
