Question: I keep getting these errors when I run my code assign6.o: In function `main': assign6.cpp:(.text+0x24): undefined reference to `Queue ::Queue()' assign6.cpp:(.text+0x49): undefined reference to `std::ostream&

I keep getting these errors when I run my code

assign6.o: In function `main': assign6.cpp:(.text+0x24): undefined reference to `Queue::Queue()' assign6.cpp:(.text+0x49): undefined reference to `std::ostream& operator<< (std::ostream&, Queue const&)' assign6.cpp:(.text+0x6a): undefined reference to `Queue::size() const' assign6.cpp:(.text+0xac): undefined reference to `Queue::capacity()' assign6.cpp:(.text+0xee): undefined reference to `Queue::empty() const' assign6.cpp:(.text+0x147): undefined reference to `Queue::~Queue()' assign6.cpp:(.text+0x15a): undefined reference to `Queue::~Queue()' collect2: error: ld returned 1 exit status Makefile:11: recipe for target 'assign6' failed make: *** [assign6] Error 1

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Queue.h file

#ifndef QUEUE_H #define QUEUE_H

#include #include

template class Queue;

template std::ostream & operator <<(std::ostream &, const Queue &);

template

class Queue { friend std::ostream & operator<< <>(std::ostream &, const Queue &);

private: T* queArray; size_t queCapacity; size_t queSize;

int frontQ;

int backQ;

public: Queue(); ~Queue();

Queue(const Queue&); Queue & operator =(const Queue &);

void clear();

size_t size()const; size_t capacity(); bool empty()const;

};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Queue.cpp

#include "Queue.h"

//default constructor template Queue::Queue() { queSize = 0; queCapacity = 0; queArray = NULL; frontQ = 0; backQ = queCapacity-1; }

//copy constructor template Queue::Queue(const Queue &other) { queSize = other.queSize; queCapacity = other.queCapacity

queArray = new T[queCapacity];

frontQ = other.frontQ; backQ = other.backQ;

for(int i = 0; i < other.queSize; i++) { queArray[i] = other[i]; } }

template size_t Queue::size()const { return queSize; }

template size_t Queue::capacity() { return queCapacity; }

template bool Queue::empty()const { if(queSize = 0) { return true; }

else { return false; } }

template Queue::~Queue() { delete []queArray; }

template Queue& Queue::operator =(const Queue &other) { this->queArray = other.queArray; this->queSize = other.queSize; this->queCapacity = other.queCapacity;

for(int i = 0; i < queSize; i++) { this->queArray[i] = other[i]; }

return *this; }

template std::ostream & operator<<(std::ostream &leftObj, const Queue &rightObj) { size_t current,i; for(current = rightObj.frontQ, i = 0; i < rightObj.queSize; ++i) { leftObj << rightObj.queArray[current] << ' ';

current = (current + 1)% rightObj.queCapacity; }

return leftObj; }

////////////////////////////////////////////////////////////////////////////////////////////////

Testfile assign6.cpp

#include #include #include "Queue.h"

using std::cout; using std::endl; using std::underflow_error;

int main() { cout << "Testing default constructor "; Queue q1;

cout << "q1: " << q1 << endl; cout << "q1 size: " << q1.size() << endl; cout << "q1 capacity: " << q1.capacity() << endl; cout << "q1 is " << ((q1.empty()) ? "empty " : "not empty "); cout << endl;

return 0;

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////

desired output

Testing default constructor q1: q1 size: 0 q1 capacity: 0 q1 is empty

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!