[問題] reference的使用問題

看板C_and_CPP作者 (大鯨魚)時間11年前 (2014/02/08 11:34), 編輯推噓0(007)
留言7則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Dev C++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 呼叫function 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 出現訊息: undefined reference to'insertionSort(int*,int)' Id return 1 exit status 程式碼(Code):(sGossiping 請善用置底文網頁, 記得排版) #include <iostream> using namespace std; void DisplayArray(int [],int); void InsertionSort(int [],int); int main() { const int MaxSize=10; int array[MaxSize]={1,2,3,4,5,6,7,8,9,10}; DisplayArray(array,MaxSize); InsertionSort(array,MaxSize);//這裡出錯 DisplayArray(array,MaxSize); return 0; } void DisplayArray(int vec[],int size){} void InsertionSort(int vec[],int size){} //我把function內容刪掉節省版面, 補充說明(Supplement): 這是網路大學的授課題目,另外請教版友InsertionArray功能假設為排序, 他是否應該要return數值? 再次發問,因為目前沒看到解答,function void InsertionSort(int vec[],int size) { for (int jdx =1;jdx<size;jdx++) { int key=vec[jdx]; int mdx=jdx-1; while (mdx >= 0 && vec[mdx]>key) { vec[mdx+1]=vec[mdx]; --mdx; } //為何此處不用將array回傳至int main仍可以作用,而用void -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.252.179.184

02/08 11:39, , 1F
錯在你函數名字不一樣.
02/08 11:39, 1F

02/08 12:16, , 2F
前面叫InsertionSort後面卻叫InsertionArray @@
02/08 12:16, 2F

02/08 12:22, , 3F
感謝,我知道錯了(跪)
02/08 12:22, 3F

02/08 12:22, , 4F
終於看懂那句undefined是甚麼意思了QQ
02/08 12:22, 4F

02/08 12:24, , 5F
請版主幫我刪文維護版面清潔感謝
02/08 12:24, 5F

02/08 19:22, , 6F
如果要刪文你一開使就不要發文就好了
02/08 19:22, 6F
想說這個錯大家應該不會犯

02/08 22:11, , 7F
我猜那錯誤訊息應該是 ld 不是 Id
02/08 22:11, 7F
※ 編輯: iamchao 來自: 111.252.160.186 (02/09 17:37) ※ 編輯: iamchao 來自: 111.252.160.186 (02/10 17:31)
文章代碼(AID): #1IzQN58b (C_and_CPP)