|
-
April 11th, 2011, 08:02 PM
#1
Trouble with Linking to Object File Undefined Reference.
Im having issues on my program assignment. I keep getting errors like
undefined reference to `void get_list<int, std::less<int> >(std::vector<int, std::allocator<int> >&, char const*, std::less<int>)'
I have a header file, and a CC file. It compiles fine but it will not link for some reason. Here is my code
Code:
#include "340.h"
#ifndef H_PROG7
#define H_PROG7
// data files
#define D1 "prog7.d1"
#define D2 "prog7.d2"
#define D3 "prog7.d3"
#define INT_SZ 4 // width of integer
#define FLT_SZ 7 // width of floating-pt number
#define STR_SZ 12 // width of string
#define INT_LN 15 // no of integers on single line
#define FLT_LN 9 // no of floating-pt nums on single line
#define STR_LN 5 // no of strings on single line
// function prototypes
template<class T,class P> void insert(vector<T>&, const T&, P);
template<class T,class P> T remove(vector<T>&, P);
template<class T,class P> void upheap(vector<T>&, int, P);
template<class T,class P> void downheap(vector<T>&, int, P);
template<class T,class P>
void get_list(vector<T>&, const char*, P);
template<class T,class P>
void print_list(vector<T>&, const int, const int, P);
template<class T, class P>
void get_list(vector<T>& v, const char* file, P func) {
ifstream inFile("file");
T data;
while(inFile >> data) {
inFile >> data;
insert(v, data, func);
}
}
template<class T, class P>
void insert(vector<T>& v, const T& data, P func) {
v.push_back( data );
upheap( v, v.size()-1, func );
}
template<class T,class P>
void upheap(vector<T>& v, int start, P func) {
while( start <= v.size()/2 ) {
unsigned int parent = start / 2;
if( parent - 1 <= v.size() && v[parent - 1] > v[parent] )
parent = parent - 1;
if( v[start] <= v[parent] )
break;
swap( v[start], v[parent] );
start = parent;
}
}
template<class T,class P>
void downheap(vector<T>& v, int start, P func) {
while(start <= v.size()/2 ) {
unsigned int child = 2 * start;
if( child + 1 <= v.size() && v[child + 1] > v[child])
child = child + 1;
if( v[start] >= v[child] )
break;
swap( v[start], v[child] );
start = child;
}
}
template<class T,class P>
T remove(vector<T>& v, P func) {
swap( v[0], v.back() );
T& item = v.back();
v.pop_back();
downheap( v, 1, func );
return item;
}
template<class T,class P>
void print_list(vector<T>& v, const int size, const int line, P func) {
for(int i = 1; i < v.size(); i++) {
cout << remove(v, func) << " ";
}
}
#endif
That is my header file.
Here is my CC File.
Code:
#include "/home/turing/onyuksel/courses/340/progs/11s/p8/prog8.h"
int main()
{
vector<int> v1(1); // heap of integers
vector<float> v2(1); // heap of floating-pt nums
vector<string> v3(1); // heap of strings
// print header message
cout << "\t\t\t*** CSCI 340: Program 8 - Output ***\n\n";
// sort and print first list
cout << "first list - ascending order:\n\n";
get_list(v1, D1, less<int>());
print_list(v1, INT_SZ, INT_LN, less<int>());
cout << "first list - descending order:\n\n";
get_list(v1, D1, greater<int>());
print_list(v1, INT_SZ, INT_LN, greater<int>());
// sort and print second list
cout << "second list - ascending order:\n\n";
get_list(v2, D2, less<float>());
print_list(v2, FLT_SZ, FLT_LN, less<float>());
cout << "second list - descending order:\n\n";
get_list(v2, D2, greater<float>());
print_list(v2, FLT_SZ, FLT_LN, greater<float>());
// sort and print third list
cout << "third list - ascending order:\n\n";
get_list(v3, D3, less<string>());
print_list(v3, STR_SZ, STR_LN, less<string>());
cout << "third list - descending order:\n\n";
get_list(v3, D3, greater<string>());
print_list(v3, STR_SZ, STR_LN, greater<string>());
// print termination message
cout << "\t\t\t*** end of program execution ***\n\n";
return 0;
}
I cant figure it out. If anyone could help me out. I have been looking at this program for hours and hours.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|