| | |
where is my error coming from?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 62
Reputation:
Solved Threads: 0
csci>g++ -c queue.cpp
csci>g++ queue.o project6.cpp
Undefined first referenced
symbol in file
Queue<int>::return_index() /var/tmp//ccHbZwrM.o
Queue<int>::enqueue(int) /var/tmp//ccHbZwrM.o
Queue<int>::dequeue() /var/tmp//ccHbZwrM.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
These are my errors. As you can see, my implementation file compiles, but does not compile with the client program. What is going on? I checked all the templates and they seem fine. Can anyone point me the right direction.
queue.h
queue.cpp(implementation file)
project6.cpp(client file)
csci>g++ queue.o project6.cpp
Undefined first referenced
symbol in file
Queue<int>::return_index() /var/tmp//ccHbZwrM.o
Queue<int>::enqueue(int) /var/tmp//ccHbZwrM.o
Queue<int>::dequeue() /var/tmp//ccHbZwrM.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
These are my errors. As you can see, my implementation file compiles, but does not compile with the client program. What is going on? I checked all the templates and they seem fine. Can anyone point me the right direction.
queue.h
c++ Syntax (Toggle Plain Text)
#ifndef QUEUE_H #define QUEUE_H const int MAX = 100; template <class Item> class Queue{ public: Queue() { front = 0; rear = MAX - 1; count = 0; data[MAX] = 0; } void display(); void enqueue(Item); Item dequeue(); int return_index(); private: Item data[MAX]; int front, count, rear; int next_index(int i) { return (i + 1) % MAX; } }; #endif
queue.cpp(implementation file)
c++ Syntax (Toggle Plain Text)
#include "queue.h" #include <iostream> using namespace std; template <class Item> void Queue<Item>::display() { int index = front; for (int i = 0; i < count; ++i) { cout << data[index] << endl; index = next_index(index); } } template <class Item> void Queue<Item>::enqueue(Item entry) { rear = next_index(rear); data[rear] = entry; ++count; } template <class Item> Item Queue<Item>::dequeue() { Item dequeued; dequeued = data[front]; front = next_index(front); --count; return dequeued; } template <class Item> int Queue<Item>::return_index() { return count; }
project6.cpp(client file)
c++ Syntax (Toggle Plain Text)
#include <iostream> #include "queue.h" #include <iomanip> using namespace std; int get_lowest(Queue<int> [], int); int main() { int qs_pair, maxtran, prob, dur, seed; int count(0); // The number of customers served int entry_time(0); // When each served customer arrived int wait_sum(0); // Sum of waiting times cout << "how many queue/server pair(s)? "; cin >> qs_pair; cout << "\nthe max time for customer transaction --> "; cin >> maxtran; cout << "\nthe probability a customer will arrive --> "; cin >> prob; cout << "\nduration of simulation(at least 1) --> "; cin >> dur; cout << "\nenter an integer seed --> "; cin >> seed; srand(seed); Queue<int> line[qs_pair]; //needs fixing int trans_time[qs_pair]; //time remaining in a transaction for(int i = 0; i < qs_pair; i++)// needs fixing { trans_time[i] = 0; } int lowest; int trans_time_c; // trans_time counter for(int time = 0; time < dur; time++) { cout << "Tick " << time << " " << endl; if(rand() % 100 < prob) { lowest = get_lowest(line, qs_pair); line[lowest].enqueue(time); } //good above for(trans_time_c = 0; trans_time_c < qs_pair; trans_time_c++) { if(trans_time[trans_time_c] == 0) { if(line[trans_time_c].return_index() != 0) { entry_time = line[trans_time_c].dequeue(); wait_sum += (time - entry_time); ++count; trans_time[trans_time_c] = (rand() % maxtran) + 1; } } else { trans_time[trans_time_c] -= 1; } } for(int i = 0; i < qs_pair; i++)//needs fixing { cout << "line " << i << " trans time " << trans_time[i] << endl; } cout << endl; } } int get_lowest(Queue<int> line[], int qs_pair) { int temp = line[0].return_index(); int temp_i = 0; for(int i = 0; i < qs_pair; i++) { if(line[i].return_index() == 0) return i; else if((i == qs_pair - 1) && line[qs_pair - 1].return_index() < temp) { temp = line[qs_pair - 1].return_index(); temp_i = qs_pair - 1; } else { if(line[i].return_index() > temp) { } else { temp = line[i].return_index(); temp_i = i; } } } return temp_i; }
•
•
Join Date: Mar 2009
Posts: 13
Reputation:
Solved Threads: 0
you should right away notice that it seems to be complaining about templates .... hit up either C++ Primer byt Lippman/Lajoie or Bjarne's book
keywords to search for on the web "inclusion compilation model"
to summarize "to generate an instantiation, the compiler must have acess to the source code that defines the template"
sooo .... you can try adjusting either your class definition OR your includes so that the compiler "sees" the templated code it needs to see when running through your project6 file code
keywords to search for on the web "inclusion compilation model"
to summarize "to generate an instantiation, the compiler must have acess to the source code that defines the template"
sooo .... you can try adjusting either your class definition OR your includes so that the compiler "sees" the templated code it needs to see when running through your project6 file code
"There is only one corner of the universe you can be certain of improving, and that's your own self.”
-- Aldous Huxley
-- Aldous Huxley
•
•
Join Date: Jan 2009
Posts: 62
Reputation:
Solved Threads: 0
•
•
•
•
you should right away notice that it seems to be complaining about templates .... hit up either C++ Primer byt Lippman/Lajoie or Bjarne's book
keywords to search for on the web "inclusion compilation model"
to summarize "to generate an instantiation, the compiler must have acess to the source code that defines the template"
sooo .... you can try adjusting either your class definition OR your includes so that the compiler "sees" the templated code it needs to see when running through your project6 file code
![]() |
Similar Threads
- 'Object variable or With block variable not set' Error (ASP.NET)
- Dreaded IDE #1 ERROR info. (Storage)
- Error, Cannot Complete Cd Writing Wizard (Windows Software)
- "Operation is not allowed when the object is closed" error (ASP.NET)
- Parse Error in PHP (PHP)
- Compilation error urgent? (VB.NET)
- Getting error 500 Internal Service Error..Meaning? (Web Browsers)
- help me find the error (C++)
- What Should I Do Next? (Viruses, Spyware and other Nasties)
- registry error (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: repeated output
- Next Thread: Towers of Hanoi Recursive
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





