動態產生之結構陣列的排序 |
答題得分者是:RaynorPao
|
galo
一般會員 發表:2 回覆:2 積分:0 註冊:2004-07-20 發送簡訊給我 |
我動態產生了一個cstruct的陣列s,陣列中均為cstruct的結構,陣列長度
為變數fore;但是在傳入qsort時,compiler卻一直出現 E2034 Cannot convert 'int (* (_closure )(const void *,const void *))(const void *,const void *)' to 'int (*)(const void *,const void *)' E2342 Type mismatch in parameter '__fcmp' (wanted 'int (*)(const void *,const void *)', got 'void')
這兩行錯誤訊息,以下附上程式碼請各位高手幫忙解答~~謝謝
struct cstruct //存放每點之x,y座標與RGB值 { int x,y; int r,g,b; }; int compare(const void *cmp1,const void *cmp2); void __fastcall TForm1::Button6Click(TObject *Sender) { int fore; int count=100; fore= 512*512-count; cstruct *s= new cstruct[fore]; qsort(s,fore,sizeof(cstruct),compare); } int TForm1::compare(const void *cmp1,const void *cmp2) { cstruct *a,*b; a=(cstruct*) cmp1; b=(cstruct*) cmp2; return ( a->r - b->r ); } |
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: 我動態產生了一個cstruct的陣列s,陣列中均為cstruct的結構,陣列長度 為變數fore;但是在傳入qsort時,compiler卻一直出現 E2034 Cannot convert 'int (* (_closure )(const void *,const void *))(const void *,const void *)' to 'int (*)(const void *,const void *)' E2342 Type mismatch in parameter '__fcmp' (wanted 'int (*)(const void *,const void *)', got 'void') 這兩行錯誤訊息,以下附上程式碼請各位高手幫忙解答~~謝謝struct cstruct //存放每點之x,y座標與RGB值 { int x,y; int r,g,b; }; int compare(const void *cmp1,const void *cmp2); void __fastcall TForm1::Button6Click(TObject *Sender) { int fore; int count=100; fore= 512*512-count; cstruct *s= new cstruct[fore]; qsort(s,fore,sizeof(cstruct),compare); } //int TForm1::compare(const void *cmp1,const void *cmp2) int compare(const void *cmp1,const void *cmp2) { cstruct *a,*b; a=(cstruct*) cmp1; b=(cstruct*) cmp2; return ( a->r - b->r ); } galo 你好: (1)先改成上面醬子看看行不行呢?<> (>>>>j="+IntToStr(j)+" x="+IntToStr(s[j].x)+ " y="+IntToStr(s[j].y)+" r="+IntToStr(s[j].r)+ " g="+IntToStr(s[j].g)+">ProcessMessages(); } delete [] s; } (3)請再依照自己的需求,自行修改-- Enjoy Researching & Developing -- 發表人 - RaynorPao 於 2004/08/18 23:16:58
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
galo
一般會員 發表:2 回覆:2 積分:0 註冊:2004-07-20 發送簡訊給我 |
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
galo你好:
你確定有照包大哥的方法改嗎?我測式是沒問題的。以下是程式碼,請對照是那出了錯~
int compare(const void *cmp1,const void *cmp2) { cstruct *a,*b; a=(cstruct*) cmp1; b=(cstruct*) cmp2; return ( a->r - b->r ); } void __fastcall TForm1::Button1Click(TObject *Sender) { int fore; int count=100; fore= 512*512-count; cstruct *s= new cstruct[fore]; qsort(s,fore,sizeof(cstruct),compare); } |
galo
一般會員 發表:2 回覆:2 積分:0 註冊:2004-07-20 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |