全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1039
推到 Plurk!
推到 Facebook!

動態產生之結構陣列的排序

答題得分者是:RaynorPao
galo
一般會員


發表:2
回覆:2
積分:0
註冊:2004-07-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-18 22:27:35 IP:210.192.xxx.xxx 未訂閱
我動態產生了一個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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-18 22:56:02 IP:61.221.xxx.xxx 未訂閱
引言: 我動態產生了一個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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-18 23:02:05 IP:210.192.xxx.xxx 未訂閱
仍然不行耶~"~ 錯誤訊息依然一樣
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-18 23:26:06 IP:211.76.xxx.xxx 未訂閱
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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-18 23:47:34 IP:210.192.xxx.xxx 未訂閱
真是不好意思呀~~ 我把 >
系統時間:2024-06-29 15:31:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!