2015-02-24 34 views
0

我有一個結構數組,我只是想將它傳遞給該函數以便對其進行排序。只要將結構數組傳遞給函數,我做錯了什麼?原型,調用和定義中有哪些錯誤?作爲函數的結構數組參數

注意 - 我意識到我還沒有初始化結構數組。在我的實際代碼中,數組包含來自其中的文本文件的數據。這與我所問的問題無關。所以請不要評論陣列中沒有任何東西。

這裏的代碼有點樣品,我不能去上班:

#include <iostream> 
using namespace std; 

struct checkType 
{ 
    char date[12]; 
    char checkNum[8]; 
    float amount; 
}; 

void bubbleSort(checkType, const int); 

int main() 
{ 
    const int NUM = 5; 
    checkType checkArray[NUM]; 

    bubbleSort(checkArray, NUM); 

    return 0; 
} 

void bubbleSort(checkType array[], const int SIZE) 
{ 
    bool swap; 
    checkType temp; 

    do 
    { 
     swap = false; 

     for (int count = 0; count < (SIZE - 1); count++) 
     { 
      if (strcmp(array[count].date, array[count + 1].date) > 0) 
      { 
       temp = array[count]; 
       array[count] = array[count + 1]; 
       array[count + 1] = temp; 
       swap = true; 
      } 
     } 
    } while (swap); 

} 

此代碼生成此錯誤:

error C2664: 'void bubbleSort(checkType,const int)' : cannot convert argument 1 from 'checkType [5]' to 'checkType'

於是我試圖改變從函數調用bubbleSort(checkArray, NUM);bubbleSort(checkArray[NUM], NUM);

這段代碼產生這些錯誤:

error LNK2019: unresolved external symbol "void __cdecl bubbleSort(struct checkType,int)" ([email protected]@[email protected]@[email protected]) referenced in function _main

error LNK1120: 1 unresolved externals

有人能解釋我在做什麼錯嗎?

+0

只要執行'MY_STRUCT_TYPE ** array' – 2015-02-24 01:55:05

回答

7

向前聲明:

void bubbleSort(checkType, const int); 

定義:

void bubbleSort(checkType array[], const int SIZE) 

這些都是不一樣的。正向聲明應該是:

void bubbleSort(checkType[], const int);