🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #737

g++ and qsort

#737
From: Alain M. Gaudrault
Date: Tue, 22 Aug 1995 09:09
38 lines
2235 bytes
	I'm having a tough time using the C qsort function within a C++
class.  I have the following array of pointers:

   static dataItemType** dataBlockVectorA = NULL;

(which I initialize before the call to qsort, obviously), then further on
down, I call:

   qsort( dataBlockVectorA, dataBlockSize, sizeof( dataItemType*), pcompfunc);

where pcompfunc is defined as follows:

   int transformDataC::pcompfunc( dataItemType** item1, dataItemType** item2);

As can be seen, the ordering function required by qsort is a member function,
and in this case needs to be so as it makes use of other class members.  The
actual call to qsort is also within a member function of the same class.
Problem is, this won't compile.  g++ indicates that:

transformData.C: In method `void transformDataC::algorithmC()':
transformData.C:165: incompatible pointer types for argument 4 of `int qsort(void *, long unsigned int, long unsigned int, int (*)(const void *, const void *))'

Yet, if I create a dummy ordering function with the same type declarations,
but *not* a member function of the class, g++ doesn't complain.  So it seems
that there's a conflict somewhere because I'm trying to use a class member as
an ordering function as opposed to a non-class member.  Is there some sort of
workaround, solution of ANY kind other than writing my own qsort routine?

Details: I'm using gcc 2.5.8 under SunOS 4.1.2

                                                 Big Al the Devil's Pal!!
                                                    __   __            
                                                   /  `-' /          ,,
                                                   |[====|||||||||||[::}
                                                   \__.-._\          ``

                                            http://ccnga.uwaterloo.ca/~amgaudra
Technical Details
Message-ID: <DDpG3H.88M@watserv3.uwaterloo.ca>
Path: arc1-ca.pugleaf.net!watserv3.uwaterloo.ca!amgaudra

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help,comp.lang.c++
Path: arc1-ca.pugleaf.net!watserv3.uwaterloo.ca!amgaudra
From: amgaudra@ccnga.uwaterloo.ca (Alain M. Gaudrault)
Subject: g++ and qsort
Message-ID: <DDpG3H.88M@watserv3.uwaterloo.ca>
Sender: news@watserv3.uwaterloo.ca
Nntp-Posting-Host: ccnga.uwaterloo.ca
Organization: University of Waterloo
Date: Tue, 22 Aug 1995 09:09:16 GMT