J
John Doe
#include "project.h"
class ThatDoesProcessing;
typedef int (ThatDoesProcessing::*PFUNC)(int);
class ThatDoesProcessing {
public:
int ProcessThis( PFUNC pFunc ) {
int iRet = (this->*pFunc)( 2 );
return iRet;
}
};
class ThatNeedsToBeProcessed : public ThatDoesProcessing {
public:
void Test( void ) {
PFUNC pMyFunc;
pMyFunc = (PFUNC)CompareFunc;
ProcessThis( pMyFunc );
}
int CompareFunc( int i ) {
return i;
}
};
int _tmain( int /* argc */, TCHAR * /* argv[] */ ) {
ThatNeedsToBeProcessed b;
b.Test();
return 0;
}
---------------------------------------------------
The above compiles without any warnings or errors at all even
with warning level set to 4 with the MS compiler.
Compliling it with GCC version 3.3.1 (cygming special)
gives the following output:
$ make
g++ -O2 -fno-strength-reduce -I/cygdrive/m/include -I/usr/X11R6/include
-D__i386__ -DWIN32_LEAN_AND_MEAN -DX_LOCALE -D_X86_ -D__CYGWIN__
-D_XOPEN_SOURCE -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE
-D_SVID_SOURCE -D_GNU_SOURCE -c -o main.o main.cpp
main.cpp: In member function `void ThatNeedsToBeProcessed::Test()':
main.cpp:33: error: argument of type `int (ThatNeedsToBeProcessed:
(int)' does
not match `int (ThatDoesProcessing::*)(int)'
make: *** [main.o] Error 1
---------------------------------------------------
The error is on the line which reads
pMyFunc = (PFUNC)CompareFunc;
in ThatNeedsToBeProcessed::Test
I thought the whole idea of a cast was to coerce the compiler into seeing
one type as another, so why does it refuse to do so here? How do I get
around it?
Thanks in advance.
class ThatDoesProcessing;
typedef int (ThatDoesProcessing::*PFUNC)(int);
class ThatDoesProcessing {
public:
int ProcessThis( PFUNC pFunc ) {
int iRet = (this->*pFunc)( 2 );
return iRet;
}
};
class ThatNeedsToBeProcessed : public ThatDoesProcessing {
public:
void Test( void ) {
PFUNC pMyFunc;
pMyFunc = (PFUNC)CompareFunc;
ProcessThis( pMyFunc );
}
int CompareFunc( int i ) {
return i;
}
};
int _tmain( int /* argc */, TCHAR * /* argv[] */ ) {
ThatNeedsToBeProcessed b;
b.Test();
return 0;
}
---------------------------------------------------
The above compiles without any warnings or errors at all even
with warning level set to 4 with the MS compiler.
Compliling it with GCC version 3.3.1 (cygming special)
gives the following output:
$ make
g++ -O2 -fno-strength-reduce -I/cygdrive/m/include -I/usr/X11R6/include
-D__i386__ -DWIN32_LEAN_AND_MEAN -DX_LOCALE -D_X86_ -D__CYGWIN__
-D_XOPEN_SOURCE -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE
-D_SVID_SOURCE -D_GNU_SOURCE -c -o main.o main.cpp
main.cpp: In member function `void ThatNeedsToBeProcessed::Test()':
main.cpp:33: error: argument of type `int (ThatNeedsToBeProcessed:
not match `int (ThatDoesProcessing::*)(int)'
make: *** [main.o] Error 1
---------------------------------------------------
The error is on the line which reads
pMyFunc = (PFUNC)CompareFunc;
in ThatNeedsToBeProcessed::Test
I thought the whole idea of a cast was to coerce the compiler into seeing
one type as another, so why does it refuse to do so here? How do I get
around it?
Thanks in advance.