错误原型与类中的任何错误都不匹配

error prototype does not match any in class

本文关键字:错误 任何 不匹配 原型      更新时间:2023-10-16

我在NetBeans上运行这个问题。下面是我的冒泡排序算法类,包括主函数:

#include <iostream>
using namespace std;

template <class elemType>
class arrayListType
{
public:
    void BubbleSort();
private:
    elemType list[100];
    int length;
    void swap(int first, int second);
    void BubbleUp(int startIndex, int endIndex);
    void print();
    void insert();
};
template <class elemType>
void arrayListType<elemType>::BubbleUp(int startIndex, int endIndex)
{
for (int index = startIndex; index < endIndex ; index++){
    if(list[index] > list[index+1])
        swap(index,index+1);
}
} 
template <class elemType>
void arrayListType<elemType>::swap(int first, int second)
{
elemType temp;
temp = list[first];
list[first] = list[second];
list[second] = temp;
} 
template <class elemType>
void arrayListType<elemType>::insert()
{
cout<<"please type in the length: ";
cin>>length;
cout<<"please enter "<<length<<" numbers"<< endl;
for(int i=0; i<length; i++)
{
    cin>>list[i];
}
}
template <class elemType>
void arrayListType<elemType>::print()
{
    cout<<"the sorted numbers" << endl;
    for(int i = 0; i<length; i++)
    {
        cout<<list[i]<<endl;        
    }
}

错误在函数声明中表示:

template <class elemType>
void arrayListType<elemType>::BubbleSort(elemType list[], int numvalues)
{
    insert();
    int current=0;
    numvalues--;
    while(current < numvalues)
    {
        BubbleUp(current,numvalues);
        numvalues--;
    }
    print();
}

主要功能:

    int main()
    {
    arrayListType<int> list ;
    list.BubbleSort();
    }

我以前做过另一个排序算法,但它工作得很好。我该如何解决这个原型匹配问题呢

错误在这里:

template <class elemType>
void arrayListType<elemType>::BubbleSort(elemType list[], int numvalues)

在你的课上,你为这个方法写了一个原型,像这样:

void BubbleSort();

不匹配:

BubbleSort(elemType list[], int numvalues)

要解决该错误,可以从实际实现中删除参数,或者将参数添加到原型中。你的错误是不言自明的,它是抱怨原型不匹配的定义。

相关文章: