header files and .C files

This is a discussion on header files and .C files within the C++ Programming forums, part of the General Programming Boards category; can anyone tell me why i get this error when i run this code? error: /tmp/cclpzH3U.o: In function `main': /tmp/cclpzH3U.o(.text+0x77): ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    header files and .C files

    can anyone tell me why i get this error when i run this code?

    error:

    /tmp/cclpzH3U.o: In function `main':
    /tmp/cclpzH3U.o(.text+0x77): undefined reference to `queuea::queuea[in-charge](int)'
    collect2: ld returned 1 exit status



    Code:

    //queue.h

    #define T int

    class queue {
    public:
    virtual bool isempty()=0;
    virtual void enqueue(T) = 0;
    virtual T dequeue() = 0;
    };


    //queuea.h

    #include "queue.h"
    #ifndef QUEUEA_H
    #define QUEUEA_H

    using namespace std;

    class queuea : public queue{
    T *a;
    int in, out;
    int full;

    public:
    queuea();
    queuea(int size);
    ~queuea();
    bool isempty();
    void enqueue(T data);
    T dequeue();

    };



    #endif

    //queuea.C

    #include "queuea.h"

    queuea :: queuea(){
    a = new T[10];
    in = out = -1;
    full = 10;
    }

    queuea :: queuea(int size){ //constructor
    a = new T[size];
    in = out = -1;
    full = size;
    }

    queuea :: ~queuea(){ //destructor
    delete [] a;
    cout << "queue is deleted";
    }


    bool queuea :: isempty(){ //check to see if queue is empty
    return out == -1;
    }

    void queuea :: enqueue(T data){ //add a value to the queue
    if (in == full-1 || in == -1){ //error trapping for ring buffer
    a[0] = data;
    in = 0;
    if (out == -1)
    out = 0;
    }

    else a[++in] = data;
    }

    T queuea :: dequeue(){ //take out value from queue
    T temp;
    temp = a[out];

    if (out == in) //error trapping for ring buffer
    in = out = -1;
    else if (out == full-1)
    out = 0;
    else out++;

    return temp;
    }




    //dumpfifo.C

    #include <iostream>
    #include "queuea.h"
    //#include "queuel.h"

    using namespace std;

    void queuedump(queue *qptr){
    while(!qptr -> isempty())
    cout << qptr -> dequeue(); // print out values in queue
    }

    int main(){
    queue *qptr = new queuea(10); // make new queue array
    for(int i=0; i<14; i++) qptr -> enqueue(i); // fill queue
    queuedump(qptr); //empty queue

    return 0;
    }





    (By the way, sorry about the style, my instructor likes it "HIS" way with the .C and the brackets)

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    lol, im sorry, i JUST read the code posting thing!

    Code:
    //queue.h
    
    #define T int
    
    class queue {
    	public:
    		virtual bool isempty()=0;
    		virtual void enqueue(T) = 0;
    		virtual T dequeue() = 0;
    };
    
    //queuea.h
    
    #include "queue.h"
    #ifndef QUEUEA_H
    #define QUEUEA_H
    
    using namespace std;
    
    class queuea : public queue{
    	T *a;
    	int in, out;
    	int full;
    	
       public:
    	queuea();
    	queuea(int size);
    	~queuea();
    	bool isempty();
    	void enqueue(T data);
    	T dequeue();
    
    };
    
    
    
    #endif
    
    
    //queuea.C
    
    #include "queuea.h"
    
    	queuea :: queuea(){
    		a = new T[10];
    		in = out = -1;
    		full = 10;
    	}
    
    	queuea :: queuea(int size){			//constructor
    		a = new T[size];
    		in = out = -1;
    		full = size;
    	}
    	
    	queuea :: ~queuea(){			//destructor
    		delete [] a;
    		cout << "queue is deleted";
    	}
    
    
    	bool queuea :: isempty(){			//check to see if queue is empty
    		return out == -1;
    	}
    
    	void queuea :: enqueue(T data){		// add a value to the queue
    		if (in == full-1 || in == -1){	//error trapping for ring buffer
    			a[0] = data;
    			in = 0;
    			if (out == -1)
    				out = 0;
    		}
    
    		else a[++in] = data;
    	}
    
    	T queuea :: dequeue(){			//take out value from queue
    		T temp;
    		temp = a[out];
    
    		if (out == in)			//error trapping for ring buffer
    			in = out = -1;
    		else if (out == full-1)
    			out = 0;
    		else out++;
    
    		return temp;
    	}
    	
    
    //dumpfifo.C
    
    #include <iostream>
    #include "queuea.h"
    //#include "queuel.h"
    
    using namespace std;
    
    void queuedump(queue *qptr){
    	while(!qptr -> isempty())
    		cout << qptr -> dequeue();	// print out values in queue
    }
    
    int main(){
    	queue *qptr = new queuea(10);			// make new queue array
    	for(int i=0; i<14; i++) qptr -> enqueue(i);	// fill queue
    	queuedump(qptr);				//empty queue
    	return 0;
    }

    much better

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-12-2008, 10:00 AM
  2. Replies: 4
    Last Post: 12-14-2005, 01:21 PM
  3. Novice question on header files
    By hern in forum C++ Programming
    Replies: 1
    Last Post: 07-30-2005, 10:11 AM
  4. Difference between .h and .c files
    By Metalix in forum C Programming
    Replies: 9
    Last Post: 01-19-2005, 07:38 PM
  5. C header files?
    By CyC|OpS in forum C Programming
    Replies: 16
    Last Post: 09-14-2002, 08:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21