[comp.lang.c++] Resolving function pointer type mismatch ?

jeff@seas.gwu.edu (Jeff Schilling) (03/22/90)

Howdy, I have a class defined with a member that is a function pointer,
like this:

class foo {
	int (*keytest)(void *,void *)
	.
	.
public:
	foo();
};

The idea is to have a pointer to a comparison function a la [str,mem]cmp
to perform a comparison.

The problem:  I am using Zortech C++ 2.0 and in my constructor, I say

foo() { keytest = &strcmp; }

The compiler complains with a message of 

ZTCPP1 -oc:temp.tmp idxcoll
	keyTest = &strcmp;
	                 ^
"idxcoll.cpp", line 13 Syntax error: type mismatch
Had: <near *><near C++ func(<near *><void>,<near *><void>) returning><int>
and: <near *><near C func(<near *><char>,<near *><char>) returning><int>
 
--- errorlevel 1

My question is, is the compiler complaining about the C++ versus C function
type, or the arguments?  

The Zortech reference manual states that "both the arguments and return 
type must exactly match those of the function pointer _EXACTLY_"

So, what will it be?  Thanx in advance.

jeff
+---------------------------------------------------------------------------+
| Jeff Schilling            School of Engineering Computing Facility        |
| jeff@seas.gwu.edu              George Washington University               |
| uunet!gwusun!jeff                   Washington, DC  20009	            |
| (201) 994-6853                                                            |
| System Programmer							    |
+---------------------------------------------------------------------------+

bright@Data-IO.COM (Walter Bright) (03/23/90)

In article <1686@sparko.gwu.edu> jeff@seas.gwu.edu (Jeff Schilling) writes:
<	int (*keytest)(void *,void *)
<The problem:  I am using Zortech C++ 2.0 and in my constructor, I say
< keytest = &strcmp;
<The compiler complains with a message of 
<ZTCPP1 -oc:temp.tmp idxcoll
<	keyTest = &strcmp;
<	                 ^
<"idxcoll.cpp", line 13 Syntax error: type mismatch
<Had: <near *><near C++ func(<near *><void>,<near *><void>) returning><int>
<and: <near *><near C func(<near *><char>,<near *><char>) returning><int>

strcmp is prototyped in string.h as:
	int cdecl strcmp(char *,char *);
This does not match your function pointer declaration. Hence the
error message. Change the declaration of keytest to match:
	int (cdecl *keytest)(char *,char *);