2016-10-18 6 views
-1

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(); 

    } 

I前に別のソートアルゴリズムを実行しましたが、うまくいきました。このプロトタイピングマッチをどうすれば修正できますか?

答えて

0

エラーはここにある:あなたのクラスで

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

、あなたはこのように、メソッドのプロトタイプを書いた:

void BubbleSort(); 

これは一致しません:

BubbleSort(elemType list[], int numvalues) 

エラーを解決するには、実際の実装からパラメータを削除しますオンにするか、パラメータをプロトタイプに追加します。あなたのエラーは自明ですが、定義と一致しないプロトタイプについて不平を言っています。

関連する問題