You need a pointer-to-function:
void* (*OnJoinFn)(char*, char*);
In your Irc class,
class Irc
{
public:
OnJoinFn onJoin;
};
This can be assigned as you are doing above:
int main()
{
Irc irc(stuff);
irc.onJoin = join;
}
But I wonder, if you are just learning C++, do you really need a pointer-to-function? pointers-to-function are certianly legal and valid, but an unusual entity and I would typically expect to use some other mechanism. As a start, I would suggest looking in to abstract base classes:
class IIrc
{
public:
virtual void* OnJoin(const char*, const char*) = 0; // pure virtual
virtual ~IIrc() {}; // Don't forget to implement a virtual destructor in any ABC
};
class MyIrc
:
public IIrc
{
public:
void* OnJoin(const char* sender, const char* channel*)
{
// YOUR CODE HERE
}
};
int main()
{
IIrc* irc = new MyIrc;
irc->OnJoin (...);
}
I've taken the liberty of introducing const correctness in OnJoin.
You should also consider not returning a void*, which bypasses most of C++'s type safety mechanisms, but a pointer to an actual object, or another interface.
Finally, using new (and delete, which is missing here, resulting in a memory leak) is poor practice. Instead, prefer to allocate things on the stack or, if you really need dynamic allocation, use a smart pointer.
std::functionandstd::bind. There are also Boost variants.