tropostropos@hotmail.com wrote:[color=blue]
> The code as it stands generates the following warning:
>
> "test.cpp", line 22: Warning (Anachronism): Formal argument 4 of type
> extern "C" int(*)(const void*,const void*) in call to std::qsort(void*,
> unsigned, unsigned, extern "C" int(*)(const void*,const void*)) is
> being passed int(*)(const void*,const void*).
> "test.cpp", line 35: Where: While instantiating
> "Sorter<int>::InternalSort()".
> "test.cpp", line 35: Where: Instantiated from non-template code.
> 1 Warning(s) detected.
>
> If I comment out the declaration labelled "Gets Warning!" and I
> un-comment-out the declaration labelled "Wont compile!", then I get the
> following errors:
>
> "test.cpp", line 21: Error: InternalSort() is not a member of
> Sorter<T>.
> "test.cpp", line 27: Error: CompareVector(const void*, const void*) is
> not a member of Sorter<T>.
> "test.cpp", line 9: Error: Linkage specifications are allowed only at
> file level.
> "test.cpp", line 34: Where: While specializing "Sorter<int>".
> "test.cpp", line 34: Where: Specialized in non-template code.
> "test.cpp", line 9: Error: storage class extern not allowed for a
> member.
> "test.cpp", line 34: Where: While specializing "Sorter<int>".
> "test.cpp", line 34: Where: Specialized in non-template code.
> "test.cpp", line 9: Error: A declaration does not specify a tag or an
> identifier.
> "test.cpp", line 34: Where: While specializing "Sorter<int>".
> "test.cpp", line 34: Where: Specialized in non-template code.
> "test.cpp", line 9: Error: Use ";" to terminate declarations.
> "test.cpp", line 34: Where: While specializing "Sorter<int>".
> "test.cpp", line 34: Where: Specialized in non-template code.
> "test.cpp", line 9: Error: "}" expected instead of "{".
> "test.cpp", line 34: Where: While specializing "Sorter<int>".
> "test.cpp", line 34: Where: Specialized in non-template code.
> "test.cpp", line 35: Error: InternalSort is not a member of
> Sorter<int>.
> 8 Error(s) detected.[/color]
This file:
=========================
#include <stdlib.h>
class A
{
public:
int i[100];
static int cmp(const void *v1, const void *v2)
{ return(* (int *) v1 - * (int *) v2); }
};
void foo(A &a) { qsort(a.i, 100, sizeof(a.i[0]), A::cmp); }
==========================
compiles without warnings using GCC (on Solaris). Whether
or not the class is templeted should be irrelevant.
I guess the point of the warnings your compiler is giving
is that the code would not be portable to an environment
where the C and C++ compilers use different calling conventions.
But I'm not sure that the Standard allows for linkage specifiers
to trigger the use of different calling conventions in the
object code.