I'm trying to use qsort in a member function, but I get the following error
I don't know what's wrong with the following code. so I tried to put the address of operator but still it didn't work.
error C2664: 'void qsort(void *,std::size_t,std::size_t,int (__cdecl *)(const void *,const void *))': cannot convert argument 4 from 'int (__thiscall Rasterizer::* )(facet **,facet **)' to 'int (__cdecl *)(const void *,const void *)'
here are the two functions:
int Rasterizer:: Poly_Compare(facet_ptr arg1, facet_ptr arg2)
{
// this function comapares the average z's of two polygons and is used by the
// depth sort surface ordering algorithm
float z1, z2;
// dereference the poly pointers
// compute z average of each polygon
if (arg1->num_points == 3)
{
// compute average of 3 point polygon
z1 = (float)0.33333*(arg1->vertex_list[0].z +
arg1->vertex_list[1].z +
arg1->vertex_list[2].z);
}
else
{
// compute average of 4 point polygon
z1 = (float)0.25*(arg1->vertex_list[0].z +
arg1->vertex_list[1].z +
arg1->vertex_list[2].z +
arg1->vertex_list[3].z);
} // end else
// now polygon 2
if (arg2->num_points == 3)
{
// compute average of 3 point polygon
z2 = (float)0.33333*(arg2->vertex_list[0].z +
arg2->vertex_list[1].z +
arg2->vertex_list[2].z);
}
else
{
// compute average of 4 point polygon
z2 = (float)0.25*(arg2->vertex_list[0].z +
arg2->vertex_list[1].z +
arg2->vertex_list[2].z +
arg2->vertex_list[3].z);
} // end else
// compare z1 and z2, such that polys' will be sorted in descending Z order
if (z1 > z2)
return(-1);
else
if (z1 < z2)
return(1);
else
return(0);
} // end Poly_Compare
//////////////////////////////////////////////////////////////////////////////
void Rasterizer::Sort_Poly_List(void)
{
// this function does a simple z sort on the poly list to order surfaces
// the list is sorted in descending order, i.e. farther polygons first
std::sort(world_polys, num_polys_frame + world_polys, Rasterizer::Poly_Compare);
}
typedef struct facet_typ
{
int num_points; // number of vertices
int color; // color of polygon
int shade; // the final shade of color after lighting
int shading; // type of shading to use
int two_sided; // is the facet two sided
int visible; // is the facet transparent
int clipped; // has this poly been clipped
int active; // used to turn faces on and off
point_3d vertex_list[MAX_POINTS_PER_POLY]; // the points that make
// up the polygon facet
float normal_length; // holds pre-computed length of normal
} facet, *facet_ptr;