Hello friends,
As the title suggests, I am trying to make a simple linked list that has a class data type. An issue arises when I try to create the pointers needed for the list. While I am entirely unsure as to what the error signifies, I believe it occurs when I use the 'new' construct.
Here are the Error Messages:
Untitled1.cpp:(.text$_ZN4nodeC1Ev[_ZN4nodeC1Ev]+0x14): undefined reference to `Contact::Contact()'
[Error] ld returned 1 exit status
Here are my files:
main1.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include "contactlist.h"
#include <fstream>
using namespace std;
int main()
{
/*ifstream fin;
fin.open("contactlist.csv");
if ( fin.fail() )
{
cerr << "Could not open the Contact List."<<endl;
exit(1);
}
else
{
cout<<"Contact List opened sucessfully"<<endl;
}
*/
string temp;
string temp_fname;
string temp_lname;
string temp_telephone;
string temp_email;
node* n;
node* t;
node* h;
int i_string=0;
int main_comma_counter = 0;
int firstnode = 0;
while (cin>> temp)
{
cin>> temp;
getline(fin,temp);
while(main_comma_counter < 4)
{
//sorting code where temp_fname, etc are given values...
}
n = new node; //issue here (node defined in contactlist.h)
n->c_Record.set(temp_fname, temp_lname, temp_telephone, temp_email);
if(firstnode = 0)
{
t = n;
h = n; //doesn't move. this is the first (header) node.
firstnode++;
}
else
{
t->next=n; //'next' from first node points to entire 2nd node;
t=t->next; //t points to same node as n
}
i_string = 0;
main_comma_counter = 0;
temp = "";
temp_fname = "";
temp_lname = "";
temp_telephone = "";
temp_email = "";
}
return 0;
}
| |
Here are the .h and its implementation if needed.
I'd figure most of the stuff here is unrelated, but just in case I missed something...
contactlist.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <string>
#include <iostream>
#ifndef CONTACTLIST_H
#define CONTACTLIST_H
using namespace std;
class Name{
public:
Name();
string first;
string last;
void set_first( string fname );
void set_last( string lname);
private:
string fname;
string lname;
};
class Contact //also known as a Record on the assignment sheet
{
public:
Contact ();
Contact (Name person,string tel_num, string email_addr);
void set (string fname, string lname, string tel_num, string email_addr);
Name get_name ();
string get_tel ();
string get_email ();
void set_name (Name fullname);
void set_tel (string tel_num);
void set_email (string email_addr);
private:
Name name;
string telephone;
string email;
};
struct node
{
Contact c_Record;
node* next;
};
class ContactList
{
public:
ContactList();
~ContactList();
int display ( ostream& output);
int insert (Contact record_to_insert); //insert info to contact class
int insert(ContactList contact_list); //insert contact to contact list
int remove (Contact record_to_delete);
int size();
int save();
int find(ostream& output, string lname, string fname); //writes all contacts that match given info
int find(ostream& output, Contact record_to_find); //writes all contacts that match given contact
int make_empty();
};
#endif /* CONTACTLIST_H */
| |
contactlist.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include "contactlist.h"
//Functions of class Name
void Name::set_first(string fname)
{
Name::first = fname;
}
void Name::set_last(string lname)
{
Name::last = lname;
}
//End of class Name functions
//Functions of class Contact
void Contact::set(string fname, string lname, string tel_num, string email_addr)
{
name.first = fname;
name.set_first(fname);
name.last = lname;
name.set_last(lname);
set_tel(tel_num);
set_email(email_addr);
}
Name Contact::get_name()
{
return name;
}
string Contact::get_tel()
{
return telephone;
}
string Contact::get_email()
{
return email;
}
void Contact::set_name (Name fullname)
{
name = fullname;
}
void Contact::set_tel(string tel_num)
{
telephone = tel_num;
}
void Contact::set_email (string email_addr)
{
email = email_addr;
}
//End of class Contact functions
//Functions of class ContactList
//...
//End of class ContactList functions
| |
Again, from what I gather I assume the 'new' on line 100 is giving me trouble, but I am really unsure.
Any help would be appreciated!
edit:
I figured it also would be a chore to look this over since I didn't give the input file needed, which is just a .csv with one line. Anything I can change to make it easier?