错误原型与类中的任何错误都不匹配
error prototype does not match any in class
我在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)
要解决该错误,可以从实际实现中删除参数,或者将参数添加到原型中。你的错误是不言自明的,它是抱怨原型不匹配的定义。
相关文章:
- 类和构造函数中的函数根本不起作用,并且不返回任何错误
- 如果用户没有输入任何内容或输入错误,如何重新输入用户的输入?
- 我正在尝试一个傻瓜 C++ 练习,我遇到了一个错误,说类 'GraduateStudent' 没有任何名为 'advisor' 的字段
- 零四元数和任何向量都不为零的特征积,这是一个错误吗?
- 如何用 C 编译,但如果使用任何C++,则会抛出错误?
- 编译器没有显示错误,但我没有得到任何输出.怎么了?
- MSVC 错误:4 个重载中的任何一个都无法转换所有参数类型
- 我的代码中是否有任何类型的错误,因为它没有给出正确的输出
- 为什么当我没有变量或其他任何命名的东西时"no match for 'operator==' "错误?
- boost::p rogram_options 在指定意外的位置参数时不报告任何错误
- Antlr cpp 运行时 任何错误的指针转换?
- 哗啦��错误:无法识别任何一组可以驱动指定关节的控制器
- 我可以使用 try catch 语句来捕获任何错误而不是具体错误吗?
- 错误:'EM::EM(...)' 的原型与类 'EM' 中的任何原型都不匹配
- std::任何只用于移动的模板,其中副本ctor内的static_assert等于编译错误,但为什么
- 当我在将文件读取到C字符串的2D数组后尝试对任何内容进行定制时,C++分段错误
- 为什么 C++ 中的分号在插入代码开头时不显示任何错误?
- 为什么我的代码在终端中没有输出任何内容.开始新行没有错误
- PLT代码中的隔离错误.任何想法为什么
- 启动时的c++运行库错误-任何调试技巧