Compiler Error (Member Function Pointers)
Compiler Error (Member Function Pointers)
- Subject: Compiler Error (Member Function Pointers)
- From: Randy Croucher <email@hidden>
- Date: Fri, 7 Nov 2003 01:01:59 -0800
I have some code that I am porting over from other platforms to Xcode,
but I get a compiler error I do not get on any other compiler (CW or
MS). I tried to narrow this down to as simple of a case as possible.
It seems that when giving a pointer to a member function, you have to
pass the address of the function when compiling with Xcode (this is not
true with the other compilers, nor with simple non-member function
pointers). Here is a simple standalone case that you can paste into
any C++ file.
//////////////////////////////////////
class BaseObject
{
public:
};
typedef void (BaseObject::*MY_FUNC)(void);
struct MyEntry
{
MY_FUNC pfn; // routine to call (or special value)
};
class DerivedObject : public BaseObject
{
public:
static const MyEntry m_entries[];
void DoSomething();
};
const MyEntry DerivedObject::m_entries[] =
{
{ DoSomething }, // *** ERROR *** needs to be &DoSomething to
compile
{ NULL }
};
//////////////////////////////////////
I get the following error on the line above that has the *** ERROR ***
comment.
error: argument of type `void (DerivedObject::)()' does not match `void
(BaseObject::*)()'
I don't want to have to change the code (in hundreds of places) or it
will not compile on the other platforms. Am I missing something? Is
there a #pragma or compiler option? Is there some new ansi standard I
don't know about? Using a function name without the parenthesis should
be a pointer to the function (it is when it is not a member function).
Thanks,
Randy Croucher
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.