Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 的原型与类中的任何原型都不匹配_C++ - Fatal编程技术网

C++ 的原型与类中的任何原型都不匹配

C++ 的原型与类中的任何原型都不匹配,c++,C++,在编译这个程序时遇到了很多麻烦。以下是完整错误列表(如果有帮助): PriorityQueueHasAStackedQueue.cpp:16:52: error: ISO C++ forbids declaration of 'isEmpty' with no type [-fpermissive] PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const

在编译这个程序时遇到了很多麻烦。以下是完整错误列表(如果有帮助):

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>();
<代码> PrimeQueReAsAsAcKedQue.CPP:16:52:错误:ISO C++禁止声明“IsHOLL”,没有类型[fime] PriorityQueueHasAStackedQueue::isEmpty()常量 ^ PriorityQueueHasAStackedQueue.cpp:16:1:错误:“int PriorityQueueHasAStackedQueue::isEmpty()const”的原型与类“PriorityQueueHasAStackedQueue”中的任何原型都不匹配 PriorityQueueHasAStackedQueue::isEmpty()常量 ^ 在PriorityQueueHasAStackedQueue.cpp:6:0包含的文件中, 来自项目4。cpp:9: PriorityQueueHasAStackedQueue.h:22:7:错误:候选项为:bool PriorityQueueHasAStackedQueue::isEmpty()常量 bool isEmpty()常量; ^ 在project4中包含的文件中。cpp:9:0: PrimRealHaseAsActhKdQue.CPP:22:74:错误:ISO C++禁止声明“队列”,没有类型[fPrime]。 PriorityQueueHasAStackedQueue::enqueue(const ItemType和newEntry) ^ PriorityQueueHasAStackedQueue.cpp:22:1:错误:“int PriorityQueueHasAStackedQueue::enqueue(const ItemType&)”的原型与“PriorityQueueHasAStackedQueue”类中的任何原型都不匹配 PriorityQueueHasAStackedQueue::enqueue(const ItemType和newEntry) ^ 在PriorityQueueHasAStackedQueue.cpp:6:0包含的文件中, 来自项目4。cpp:9: PriorityQueueHasAStackedQueue.h:23:7:错误:候选项为:bool PriorityQueueHasAStackedQueue::enqueue(const ItemType&) bool排队(const ItemType和newEntry); ^ 在project4中包含的文件中。cpp:9:0: PrimRealHeaseAsAcKeDek.CPP:30:50:错误:ISO C++禁止声明“DEQueGeNe”,没有类型[FPrime] PriorityQueueHasAStackedQueue::dequeue() ^ PriorityQueueHasAStackedQueue.cpp:30:1:错误:“int PriorityQueueHasAStackedQueue::dequeue()”的原型与“PriorityQueueHasAStackedQueue”类中的任何原型都不匹配 PriorityQueueHasAStackedQueue::dequeue() ^ 在PriorityQueueHasAStackedQueue.cpp:6:0包含的文件中, 来自项目4。cpp:9: PriorityQueueHasAStackedQueue.h:24:7:错误:候选项为:bool PriorityQueueHasAStackedQueue::dequeue() bool-dequeue(); ^ 在project4中包含的文件中。cpp:9:0: PrimRealHaseAtaskKeDeal.CPP:48∶49:错误:ISO C++禁止声明“Pek”,没有类型[fime]。 PriorityQueueHasAStackedQueue::peek()常量 ^ PriorityQueueHasAStackedQueue.cpp:48:1:错误:“int PriorityQueueHasAStackedQueue::peek()const”的原型与类“PriorityQueueHasAStackedQueue”中的任何原型都不匹配 PriorityQueueHasAStackedQueue::peek()常量 ^ 在PriorityQueueHasAStackedQueue.cpp:6:0包含的文件中, 来自项目4。cpp:9: PriorityQueueHasAStackedQueue.h:25:11:错误:候选项为:ItemType PriorityQueueHasAStackedQueue::peek()常量 ItemType peek()常量; ^ PriorityQueueHasTackedQueue.h:在函数“void testPriorityQueue(int*,int)”中: PriorityQueueHasTackedQueue.h:21:2:错误:“PriorityQueueHasTackedQueue::PriorityQueueHasTackedQueue()[with ItemType=int]”是私有的 PriorityQueueHasTackedQueue(); ^ project4.cpp:40:79:错误:在此上下文中 PriorityQueueInterface*PQUE=new PriorityQueueHasTackedQueue(); 我尝试在.cpp文件中为它们提供返回类型,但这只会让程序认为我的所有函数都是需要指向的成员。这与我的构造函数有关吗?我真的不知道如何实现这些,所以它们可能是错的

奇怪的是,我的另一个类QueueAsatack有完全相同的布局,但我没有得到任何错误

PriorityQueueHasTackedQueue.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
\ifndef PRIORITY\u QUEUE\u具有堆叠队列_
#定义优先级队列具有堆叠队列_
#包括“PriorityQueueInterface.h”
#包括“QueueAsAStack.h”
#包括“LinkedStack.h”
模板
类PriorityQueueHasTackedQueue:公共PriorityQueueInterface
{
//私人:
PriorityQueueHasAStackedQueue*pq=新建PriorityQueueHasAStackedQueue();
PriorityQueueHasAStackedQueue*temp=new PriorityQueueHasAStackedQueue();
//公众:
PriorityQueueHasTackedQueue();
bool isEmpty()常量;
bool排队(const ItemType和newEntry);
bool-dequeue();
ItemType peek()常量;
};
#恩迪夫
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;
}
#包括“PriorityQueueHasAStackedQueue.h”
#包括“PriorityQueueInterface.h”
#包括“LinkedStack.h”
模板
PriorityQueueHasAStackedQueue::PriorityQueueHasAStackedQueue()
{
}
模板
PriorityQueueHasAStackedQueue::isEmpty()常量
{
返回pq.peek()==nullptr;
}
模板
PriorityQueueHasAStackedQueue::enqueue(const ItemType和newEntry)
{
pq.推送(新条目);
返回true;
}
模板
PriorityQueueHasAStackedQueue::dequeue()
{
而(!pq.isEmpty()){
温度推动(pq.peek());
pq.pop();
}
temp.pop();
而(!temp.isEmpty()){
质量推送(温度peek());
temp.pop();
}
返回true;
}
模板
PriorityQueueHasAStackedQueue::peek()常量
{
PriorityQueueHasTackedQueuePeeEdItem;
而(!pq.isEmpty()){
温度推动(pq.peek());
pq.pop();
}
peekedItem=临时peek();
而(!temp.isEmpty()){
质量推送(温度peek());
temp.pop();
}
返回peek-editem;
}
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
\ifndef优先级队列\u接口_
#定义优先级队列接口_
模板
类优先级队列接口
{
公众:
/**查看此优先级队列是否为空。
@如果优先级队列为空,则返回True;否则返回false*/
虚拟布尔isEmpty()常量=0;
/**将新条目添加到此优先级队列。
@post如果操作成功,则newEntry位于
公共关系
template<class ItemType>
PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const
{
    return pq.peek() == nullptr;
}
template<class ItemType>
bool PriorityQueueHasAStackedQueue<ItemType>::isEmpty() const
{
    return pq.peek() == nullptr;
}
temp.pop();
temp->pop();