T
tropostropos
On Solaris, using the Sun compiler, I get annoying warnings from the
following code. The problem is that I am passing a C++ member function
pointer to the C library function qsort. Is there a solution?
Declaring the function extern "C" fails, because linkage declarations
must be made at file scope.
#include <stdlib.h> //for qsort
template <class T>
class Sorter
{
public:
//CompareVector is passed to qsort, which requires a C function
pointer parameter.
//extern "C" { static int CompareVector (t void *otPt1, const void
*otPt2;} //Wont compile!
static int CompareVector (const void *otPt1, const void *otPt2);
//Gets warning!
void InternalSort ();
T **vptPoints;
int viNumPoints;
};
template <class T>
void Sorter<T>::InternalSort ()
{
qsort( vptPoints, viNumPoints, sizeof (T*), CompareVector
); //last param should be extern "C"!
}
template <class T>
int Sorter<T>::CompareVector (const void *otPt1, const void *otPt2)
{
return 0; //We don't bother executing it: toy code to fix
compilation warning.
}
int main()
{
Sorter<int> s;
s.InternalSort();
}
following code. The problem is that I am passing a C++ member function
pointer to the C library function qsort. Is there a solution?
Declaring the function extern "C" fails, because linkage declarations
must be made at file scope.
#include <stdlib.h> //for qsort
template <class T>
class Sorter
{
public:
//CompareVector is passed to qsort, which requires a C function
pointer parameter.
//extern "C" { static int CompareVector (t void *otPt1, const void
*otPt2;} //Wont compile!
static int CompareVector (const void *otPt1, const void *otPt2);
//Gets warning!
void InternalSort ();
T **vptPoints;
int viNumPoints;
};
template <class T>
void Sorter<T>::InternalSort ()
{
qsort( vptPoints, viNumPoints, sizeof (T*), CompareVector
); //last param should be extern "C"!
}
template <class T>
int Sorter<T>::CompareVector (const void *otPt1, const void *otPt2)
{
return 0; //We don't bother executing it: toy code to fix
compilation warning.
}
int main()
{
Sorter<int> s;
s.InternalSort();
}