Okay. Fairly complicated program involving templates, classes, and a driver program. All files are within the same directory. Pretty damn sure that all functions are defined and declaired... just not sure on the linking process with this many files. Using gnu g++ as a compiler.
ERROR ->
Code:
brooksbp@brooksbp-laptop:~/csci2270/assign5$ g++ studentDemo.cxx -o test
/tmp/ccZiNVfI.o: In function `main':
studentDemo.cxx:(.text+0x88): undefined reference to `assignment5::create_database()'
studentDemo.cxx:(.text+0x102): undefined reference to `assignment5::print_in_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
studentDemo.cxx:(.text+0x179): undefined reference to `assignment5::print_pre_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
studentDemo.cxx:(.text+0x1f0): undefined reference to `assignment5::print_post_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
studentDemo.cxx:(.text+0x26f): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0x2f6): undefined reference to `assignment5::change_major(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
studentDemo.cxx:(.text+0x3a6): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0x425): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0x4f9): undefined reference to `assignment5::change_grade(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
studentDemo.cxx:(.text+0x5a9): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0x628): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0x704): undefined reference to `assignment5::add_course(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long, int, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
studentDemo.cxx:(.text+0x7b4): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0x82b): undefined reference to `assignment5::print_perfect_gpa(assignment5::heapnode<assignment5::studentRecord, int>*)'
studentDemo.cxx:(.text+0x8aa): undefined reference to `assignment5::remove_student(assignment5::heapnode<assignment5::studentRecord, int>*&, unsigned long)'
studentDemo.cxx:(.text+0x921): undefined reference to `assignment5::print_perfect_gpa(assignment5::heapnode<assignment5::studentRecord, int>*)'
studentDemo.cxx:(.text+0xd03): undefined reference to `assignment5::add_student(assignment5::heapnode<assignment5::studentRecord, int>*&, assignment5::studentRecord const&)'
studentDemo.cxx:(.text+0xd9d): undefined reference to `assignment5::print_record(assignment5::heapnode<assignment5::studentRecord, int>*, unsigned long)'
studentDemo.cxx:(.text+0xe14): undefined reference to `assignment5::print_in_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
studentDemo.cxx:(.text+0xe93): undefined reference to `assignment5::remove_student(assignment5::heapnode<assignment5::studentRecord, int>*&, unsigned long)'
studentDemo.cxx:(.text+0xf0a): undefined reference to `assignment5::print_in_record(assignment5::heapnode<assignment5::studentRecord, int>*)'
collect2: ld returned 1 exit status
heap.h
Code:
#include <iostream>
#include <cstdlib> // Provides NULL and size_t
#include <stack>
using namespace std;
namespace assignment5
{
template <class Item, class Key>
class heapnode
{
//class stuff here
};
template <class Process, class Item, class Key>
void inorder_processing(heapnode<Item, Key> *root, Process f);
template <class Process, class Item, class Key>
void preorder_processing(heapnode<Item, Key> *root, Process f);
template <class Process, class Item, class Key>
void postorder_processing(heapnode<Item, Key> *root, Process f);
template <class Item, class Key>
bool check_node(heapnode<Item, Key>* root, Key k);
template <class Item, class Key>
void insert_node(heapnode<Item, Key>*& root, Key k, const Item& entry);
template <class Item, class Key>
void remove_node(heapnode<Item, Key>*& root, Key k);
template <class Process, class Param, class Item, class Key>
bool process_node(heapnode<Item, Key> *root, Key k, Process f, Param p);
template <class Item, class Key>
size_t size(heapnode<Item, Key> *root);
template <class Item, class Key>
heapnode<Item, Key>* freeParent(heapnode<Item, Key> *root);
template <class Item, class Key>
heapnode<Item, Key>* lastNode(heapnode<Item, Key> *root);
template <class Item, class Key>
void swap(heapnode<Item, Key> *a, heapnode<Item, Key> *b);
template <class Item, class Key>
heapnode<Item, Key>* search(heapnode<Item, Key> *root, Key k);
#include "heap.cxx"
}
heap.cxx
Code:
function declarations for all those template functions in heap.h here
ie:
template <class Process, class Item, class Key>
void inorder_processing(heapnode<Item, Key> *root, Process f)
{
if(root != NULL) {
inorder_processing(root->getLeft(), f);
f(root->getItem());
inorder_processing(root->getRight(), f);
}
}
...and so on...
studentDatabase.h
Code:
#include <iostream>
#include <cstdlib> // Provides NULL and size_t
#include <string>
#include <vector>
#include "heap.h"
using namespace std;
//new data type for SID
typedef unsigned long SID;
namespace assignment5
{
class studentRecord
{
//class stuff here
};
void add_student(heapnode<studentRecord, int>*& root, const studentRecord& record);
bool remove_student(heapnode<studentRecord, int>*& root, SID id);
bool print_record(heapnode<studentRecord, int>* root, SID id);
void print_in_record(heapnode<studentRecord, int>* root);
void print_pre_record(heapnode<studentRecord, int>* root);
void print_post_record(heapnode<studentRecord, int>* root);
void print_perfect_gpa(heapnode<studentRecord, int>* root);
bool add_course(heapnode<studentRecord, int>* root, SID id, int c_num, int c_hours, string grade);
bool change_major(heapnode<studentRecord, int>* root, SID id, string new_major);
bool change_grade(heapnode<studentRecord, int>* root, SID id, int c_num, string new_grade);
heapnode<studentRecord, int>* create_database();
}
studentDatabase.cxx
Code:
#include <iostream> // Provides cin and cout
#include <cstdlib> // Provides EXIT_SUCCESS
#include "studentDatabase.h"
using namespace std;
namespace assignment5
{
//FUNCTION DECLARATIONS HERE SUCH AS THE FOLLOWING ->
void add_student(heapnode<studentRecord, int>*& root, const studentRecord& record)
{
SID sid = record.get_sid();
insert_node(root, sid, record);
}
}
studentDemo.cxx
Code:
#include <iostream> // Provides cin and cout
#include <cstdlib> // Provides EXIT_SUCCESS
#include "studentDatabase.h"
using namespace std;
using namespace assignment5;
int main( )
{
heapnode<studentRecord, int> *mydb;
mydb = create_database( );
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT RECORDS IN IN-ORDER" << endl;
cout << "------------------------------------" << endl;
print_in_record(mydb);
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT RECORDS IN PRE-ORDER" << endl;
cout << "------------------------------------" << endl;
print_pre_record(mydb);
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT RECORDS IN POST-ORDER" << endl;
cout << "------------------------------------" << endl;
print_post_record(mydb);
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF A SPECIFIC STUDENT" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 139057);
cout << "------------------------------------" << endl;
cout << "CHANGE MAJOR OF THE STUDENT" << endl;
change_major(mydb, 139057, "Electrical Engineering");
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF THE STUDENT WITH CHANGED MAJOR" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 139057);
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF A SPECIFIC STUDENT" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 992654);
cout << "------------------------------------" << endl;
cout << "CHANGE GRADE OF THE STUDENT" << endl;
cout << "------------------------------------" << endl;
change_grade(mydb, 992654, 5463, "B+");
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF THE STUDENT WITH CHANGED GRADE" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 992654);
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF A SPECIFIC STUDENT" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 448720);
cout << "------------------------------------" << endl;
cout << "ADD A COURSE TO THE STUDENT RECORD" << endl;
cout << "------------------------------------" << endl;
add_course(mydb, 448720, 2463, 4, "B-");
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF THE STUDENT WITH COURSE ADDED" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 448720);
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT ID AND NAMES OF STUDENTS WITH PERFECT GPA"
<< endl;
cout << "------------------------------------" << endl;
print_perfect_gpa(mydb);
cout << "------------------------------------" << endl;
cout << "REMOVING A STUDENT RECORD" << endl;
cout << "------------------------------------" << endl;
remove_student(mydb, 810001);
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT ID AND NAMES OF STUDENTS WITH PERFECT GPA"
<< endl;
cout << "------------------------------------" << endl;
print_perfect_gpa(mydb);
cout << "------------------------------------" << endl;
cout << "ADDING A NEW STUDENT RECORD" << endl;
cout << "------------------------------------" << endl;
/* NOTE: You will have to modify the following, depending on
your definitions of courseList and studentRecord */
studentRecord s;
s.set_sid(999999);
s.set_name("Thomas L. Jackson");
s.set_major("Computer Science");
s.add_course(4567, 4, "B-");
s.add_course(2220, 3, "A");
s.add_course(5621, 2, "A-");
s.add_course(4578, 3, "C+");
add_student(mydb, s);
cout << "------------------------------------" << endl;
cout << "PRINTING RECORD OF THE NEW STUDENT" << endl;
cout << "------------------------------------" << endl;
print_record(mydb, 999999);
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT RECORDS IN IN-ORDER" << endl;
cout << "------------------------------------" << endl;
print_in_record(mydb);
cout << "------------------------------------" << endl;
cout << "REMOVING A STUDENT RECORD" << endl;
cout << "------------------------------------" << endl;
remove_student(mydb, 323251);
cout << "------------------------------------" << endl;
cout << "PRINTING STUDENT RECORDS IN IN-ORDER" << endl;
cout << "------------------------------------" << endl;
print_in_record(mydb);
return EXIT_SUCCESS;
}