--- In [email protected], "Rick Bowers" <[EMAIL PROTECTED]> wrote:
>
> On 6/29/08, John Matthews <[EMAIL PROTECTED]> wrote:
>
> > --- In [email protected], "John Matthews" <jm5678@> wrote:
> > >
> > > --- In [email protected], "Rick Bowers" <Mowgli53@> wrote:
> > > >
> > > > I am trying to sort an array of pointers to a structure.
> > >
> > > Hi Rick- below is an example program
> >
> > Sorry, minor correction:
>
> Thanks, John.
>
> I tried compiling your code and got the same basic errors I was
getting when
> I tried this;
> D:\Work\sorting.cpp In function `int compareEntry(const void*,
const
> void*)':
> 39 D:\Work\sorting.cpp invalid conversion from `const void*' to `const
> ENTRY*'
Ah, looks like you're using C++, and IIRC C++ doesn't allow implicit
conversions from void * to non-void * without casts, which is what my
C code is doing.
I'm not going to try to convert my code to C++ - hopefully someone
else who knows what they're talking about will be able to do that.
However, for a single call solution in C, change the array of pointers
qsort() function to:
static int compareEntryPtr(const void *a, const void *b)
{
const ENTRY *e1 = *(ENTRY **)a;
const ENTRY *e2 = *(ENTRY **)b;
printf("comparing %c %c\n", e1->c, e2->c);
if (e1->c < e2->c) return -1;
if (e1->c > e2->c) return 1;
return 0;
}
I think that (or something pretty close) should work in C++, because
it doesn't involve any implicit void * casts. Good luck :-)