2016-10-18 2 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

오류는 여기에 있습니다 :이 일치하지 않는

void BubbleSort(); 

: 클래스에서

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

, 당신은이 같은 방법에 대한 프로토 타입을 썼다

BubbleSort(elemType list[], int numvalues) 

오류를 해결하려면 실제 구현에서 매개 변수를 제거하십시오. 켜거나 매개 변수를 프로토 타입에 추가하십시오. 당신의 실수는 자명하다. 정의와 일치하지 않는 프로토 타입에 대해 불평하고있다.

관련 문제