Original Post
It seems that almost every time I look at a function pointer tutorial dealing with member functions, it ALWAYS explains how to get a pointer on the outside to reference to a function inside a class. This leads me to assume that standard function pointer syntax applies when you're getting a function pointer inside Class A to point to a function inside Class A. Except that doesn't want to work either. What I'm trying to do here is create a function that will clear out a linked list. Optionally, it will call a function for each node in the list just before it's cleared out. Snippet with changed identifiers: The error I get from the marked line is (using Visual Studio .NET 2003) error C2664: 'cClass::EmptyList' : cannot convert parameter 1 from 'void (cClass::sNode *)' to 'void (__cdecl *)(cClass::sNode *)' No errors occur when the offending line is commented out. The line in the destructor works just fine. I have tried a very large number of things, one such thing being moving the function pointer from being a function parameter to a member variable. Nothing's worked so far. Anyone know what to do?
cClass
{
struct sNode; // Contents not important
void EmptyList(void (* nodefunc)(sNode*))
{
sNode* tmp;
// Code to carry tmp through the linked list
if( nodefunc != NULL ) nodefunc(tmp); // Executed for each node
}
void Func(sNode* node)
{
// code using the node
}
~cClass()
{
EmptyList(NULL);
}
void ClearWithFunc()
{
EmptyList(Func); // *** ERROR ***
}
};