[問題] reference的使用問題
開發平台(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
02/08 12:16, 2F
→
02/08 12:22, , 3F
02/08 12:22, 3F
→
02/08 12:22, , 4F
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
02/08 22:11, 7F
※ 編輯: iamchao 來自: 111.252.160.186 (02/09 17:37)
※ 編輯: iamchao 來自: 111.252.160.186 (02/10 17:31)