Having a lot of trouble getting this program to compile. Here's a list of the full error if that helps:
PriorityQueueHasAStackedQueue.cpp:16:52: error: ISO C++ forbids declaration of 'isEmpty' with no type [-fpermissive]
PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const
^
PriorityQueueHasAStackedQueue.cpp:16:1: error: prototype for 'int PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const' does not match any in class 'PriorityQueueHasAStackedQueue<ItemType>'
PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const
^
In file included from PriorityQueueHasAStackedQueue.cpp:6:0,
from project4.cpp:9:
PriorityQueueHasAStackedQueue.h:22:7: error: candidate is: bool PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const
bool isEmpty() const;
^
In file included from project4.cpp:9:0:
PriorityQueueHasAStackedQueue.cpp:22:74: error: ISO C++ forbids declaration of 'enqueue' with no type [-fpermissive]
PriorityQueueHasAStackedQueue<ItemType>::enqueue(const ItemType& newEntry)
^
PriorityQueueHasAStackedQueue.cpp:22:1: error: prototype for 'int PriorityQueueHasAStackedQueue<ItemType>::enqueue(const ItemType&)' does not match any in class 'PriorityQueueHasAStackedQueue<ItemType>'
PriorityQueueHasAStackedQueue<ItemType>::enqueue(const ItemType& newEntry)
^
In file included from PriorityQueueHasAStackedQueue.cpp:6:0,
from project4.cpp:9:
PriorityQueueHasAStackedQueue.h:23:7: error: candidate is: bool PriorityQueueHasAStackedQueue<ItemType>::enqueue(const ItemType&)
bool enqueue(const ItemType& newEntry);
^
In file included from project4.cpp:9:0:
PriorityQueueHasAStackedQueue.cpp:30:50: error: ISO C++ forbids declaration of 'dequeue' with no type [-fpermissive]
PriorityQueueHasAStackedQueue<ItemType>::dequeue()
^
PriorityQueueHasAStackedQueue.cpp:30:1: error: prototype for 'int PriorityQueueHasAStackedQueue<ItemType>::dequeue()' does not match any in class 'PriorityQueueHasAStackedQueue<ItemType>'
PriorityQueueHasAStackedQueue<ItemType>::dequeue()
^
In file included from PriorityQueueHasAStackedQueue.cpp:6:0,
from project4.cpp:9:
PriorityQueueHasAStackedQueue.h:24:7: error: candidate is: bool PriorityQueueHasAStackedQueue<ItemType>::dequeue()
bool dequeue();
^
In file included from project4.cpp:9:0:
PriorityQueueHasAStackedQueue.cpp:48:49: error: ISO C++ forbids declaration of 'peek' with no type [-fpermissive]
PriorityQueueHasAStackedQueue<ItemType>::peek() const
^
PriorityQueueHasAStackedQueue.cpp:48:1: error: prototype for 'int PriorityQueueHasAStackedQueue<ItemType>::peek() const' does not match any in class 'PriorityQueueHasAStackedQueue<ItemType>'
PriorityQueueHasAStackedQueue<ItemType>::peek() const
^
In file included from PriorityQueueHasAStackedQueue.cpp:6:0,
from project4.cpp:9:
PriorityQueueHasAStackedQueue.h:25:11: error: candidate is: ItemType PriorityQueueHasAStackedQueue<ItemType>::peek() const
ItemType peek() const;
^
PriorityQueueHasAStackedQueue.h: In function 'void testPriorityQueue(int*, int)':
PriorityQueueHasAStackedQueue.h:21:2: error: 'PriorityQueueHasAStackedQueue<ItemType>::PriorityQueueHasAStackedQueue() [with ItemType = int]' is private
PriorityQueueHasAStackedQueue();
^
project4.cpp:40:79: error: within this context
PriorityQueueInterface<int>* pQueue = new PriorityQueueHasAStackedQueue<int>();
I've tried giving them return types in my .cpp file, but that just makes the program think that all my functions are members that need to be pointed to. Does this have something to do with my constructors? I really don't know how to implement those, so they're probably wrong anyway.
The weird thing is that I have the exact same layout for my other class, QueueAsAStack, but I'm not getting any errors for those.
PriorityQueueHasAStackedQueue.h:
#ifndef PRIORITY_QUEUE_HAS_A_STACKED_QUEUE_
#define PRIORITY_QUEUE_HAS_A_STACKED_QUEUE_
#include "PriorityQueueInterface.h"
#include "QueueAsAStack.h"
#include "LinkedStack.h"
template<class ItemType>
class PriorityQueueHasAStackedQueue : public PriorityQueueInterface<ItemType>
{
//private:
PriorityQueueHasAStackedQueue<int>* pq = new PriorityQueueHasAStackedQueue<int>();
PriorityQueueHasAStackedQueue<int>* temp = new PriorityQueueHasAStackedQueue<int>();
//public:
PriorityQueueHasAStackedQueue();
bool isEmpty() const;
bool enqueue(const ItemType& newEntry);
bool dequeue();
ItemType peek() const;
};
#endif
PriorityQueueHasAStackedQueue.cpp:
#include "PriorityQueueHasAStackedQueue.h"
#include "PriorityQueueInterface.h"
#include "LinkedStack.h"
template<class ItemType>
PriorityQueueHasAStackedQueue<ItemType>::PriorityQueueHasAStackedQueue()
{
}
template<class ItemType>
PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const
{
return pq.peek() == nullptr;
}
template<class ItemType>
PriorityQueueHasAStackedQueue<ItemType>::enqueue(const ItemType& newEntry)
{
pq.push(newEntry);
return true;
}
template<class ItemType>
PriorityQueueHasAStackedQueue<ItemType>::dequeue()
{
while(!pq.isEmpty()){
temp.push(pq.peek());
pq.pop();
}
temp.pop();
while(!temp.isEmpty()){
pq.push(temp.peek());
temp.pop();
}
return true;
}
template<class ItemType>
PriorityQueueHasAStackedQueue<ItemType>::peek() const
{
PriorityQueueHasAStackedQueue<int> peekedItem;
while(!pq.isEmpty()){
temp.push(pq.peek());
pq.pop();
}
peekedItem = temp.peek();
while(!temp.isEmpty()){
pq.push(temp.peek());
temp.pop();
}
return peekedItem;
}
PriorityQueueInterface.h:
#ifndef PRIORITY_QUEUE_INTERFACE_
#define PRIORITY_QUEUE_INTERFACE_
template<class ItemType>
class PriorityQueueInterface
{
public:
/** Sees whether this priority queue is empty.
@return True if the priority queue is empty, or false if not. */
virtual bool isEmpty() const = 0;
/** Adds a new entry to this priority queue.
@post If the operation was successful, newEntry is in the
priority queue.
@param newEntry The object to be added as a new entry.
@return True if the addition is successful or false if not. */
virtual bool enqueue(const ItemType& newEntry) = 0;
/** Removes from this priority queue the entry having the
highest priority.
@post If the operation was successful, the highest priority
entry has been removed.
@return True if the removal is successful or false if not. */
virtual bool dequeue() = 0;
/** Returns the highest-priority entry in this priority queue.
@pre The priority queue is not empty.
@post The highest-priority entry has been returned, and the
priority queue is unchanged.
@return The highest-priority entry. */
virtual ItemType peek() const = 0;
/** Destroys object and frees memory allocated by object. */
virtual ~PriorityQueueInterface() { }
}; // end PriorityQueueInterface
#endif
I've tried so many things to try and fix it but I just have no idea.