--- In [email protected], "Indika Bandara" <[EMAIL PROTECTED]>
wrote:
>
> #define MAX_NUM 5
>  
> struct P
> {
>  
>         P(){};
>         P(int i){_i = i; };
>         int _i;
> };
>  
> int Comp(const void* p1, const void* p2)
> {
>         P* i1 = (P*)p1;
>         P* i2 = (P*)p2;
>         if(i1->_i>i2->_i)
>                 return 1;
>         if(i1->_i<i2->_i)
>                 return -1;
>  
>         return 0;
> }
>  
> int main(int argc, char** argv)
> {
>         P** p = new P*[MAX_NUM];
>         p[0] = new P(1);
>         p[1] = new P(9);
>         p[2] = new P(8);
>         p[3] = new P(3);
>         p[4] = new P(2);
>         printf("before\n");
>         for(int i=0; i<MAX_NUM; i++)
>                 printf("%d\n", p[i]->_i);
>  
>         qsort(p, MAX_NUM, sizeof(P*), Comp);

Shouldn't it be "sizeof( P)"?

>         printf("after\n");
>         for(int i=0; i<MAX_NUM; i++)
>                 printf("%d\n", p[i]->_i);
>  
> }
<snip>

Regards,
Nico

Reply via email to