I wonder if it is possible to use pointers to friend functions. I wrote a code that tried to do it, but I wasn't able to compile it until I changed that function to regular function.
is the friend function a global function or a member function of a class?
if it is global simply do this:
1 2 3
void *myfunctptr = myfunct; //provided it is not overloaded
//am not so sure if it is a member function of another class, you can try the following
void *myfunctptr = myclass::myfunct;
That function is missing a few arguments, that function is a member of a class that has no instance named sum, and... you know what, here's a link for you to read: http://cplusplus.com/doc/tutorial/classes/
There seem to be a number of misunderstandings in the snippet posted. I suggest reading up on both friend functions and static methods to start.
As far as passing the member function as an argument, I would recommend against it altogether. It can be done but I suspect there are better solutions at your disposal.
I have not written this post without prior searching for solution in other materials. Maybe I'm missing something very basic, but I would really appreciate if someone could point that specifically ... not sending me to some other vague places ...
And once again sum is not a member function, it is friend function.
Thank You for responses. Indeed moving definitions out from class declaration solves compilation problem. But it is first time that I hear that friends have to be defined outside of class. Very interesting ...
OK, I looked at that a bit more and found out that neither of solutions given here so far is correct. The problem is a bit different. To show that you can simple divide the code I showed before into 3 files
* myclass.h with class declaration
* myclass.cpp with class methods and friend functions definitions
* main.cpp
In that configuration it will give the same error as the beginning.
The true problem is with friend function scope -- check Stroustrup - The C++ Programming Language 11.5.1. Basically friend functions are not in scope and solution is to put declarations of friend functions once again before main (lines 42, 43; difference doesn't second declaration because definition is in scope).