gpt4 book ai didi

c++ - 错误 : prototype does not match any in class

转载 作者:行者123 更新时间:2023-11-30 05:15:57 24 4
gpt4 key购买 nike

当我尝试编译我的代码时出现此错误:

Priority_queue.h:63:6: error: prototype for ‘void Priority_queue<T>::push_heap(Iterator, Iterator)’ does not match any in class ‘Priority_queue<T>’
void Priority_queue<T>::push_heap(Iterator start, Iterator stop) {
^
Priority_queue.h:31:10: error: candidate is: void Priority_queue<T>::push_heap(typename std::vector<T>::iterator, typename std::vector<T>::iterator)
void push_heap(typename vector<T>::iterator start, typename vector<T>::iterator stop);
^

Priority_queue.h

#include <vector>
using namespace std;

template <class T>
class Priority_queue {
public:
...

void push_heap(typename vector<T>::iterator start, typename vector<T>::iterator stop);
void pop_heap(typename vector<T>::iterator start, typename vector<T>::iterator stop);
void adjust_heap(typename vector<T>::iterator start, unsigned int heapSize, unsigned int position);
void make_heap(typename vector<T>::iterator start, typename vector<T>::iterator stop);
void sort_heap(typename vector<T>::iterator start, typename vector<T>::iterator stop);
void heap_sort(typename vector<T>::iterator start, typename vector<T>::iterator stop);
private:
vector<T> c;
};

template <class T>
template <class Iterator>
void Priority_queue<T>::push_heap(Iterator start, Iterator stop) {
...
}

为什么这不起作用?对于其余函数,我也遇到了相同类型的错误。

最佳答案

错误信息很清楚;贴标和定义不匹配。 push_heap 声明为类模板Priority_queue 的成员函数,但定义为类模板Priority_queue 的成员函数template>.

如何修复取决于你的初衷;您可以将声明更改为

template <class T>
class Priority_queue {
public:
...
template <class Iterator>
void push_heap(Iterator start, Iterator stop);
...
};

LIVE1

或将定义更改为

template <class T>
void Priority_queue<T>::push_heap(typename vector<T>::iterator start, typename vector<T>::iterator stop) {
...
}

LIVE2

关于c++ - 错误 : prototype does not match any in class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42896300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com