Author: Dann Corbit
Date: 09:50:25 03/23/01
Go up one level in this thread
On March 23, 2001 at 10:01:54, Peter Fendrich wrote:
>I probably should know this - kind of embarrassing....
>
>In C I sometimes used this kind of construction:
> int intParm; char strParm[100];
> void (* FP)(char *, int *);
> .
> .
> .
> FP = (void ( *)(char *, int *)) &Function; // cast to function pointer
> (*FP)(strParm, &intParm); // call the function
>
>
>In C++ I can't manage to do this.
>Anyone knows how to use a pointer to a function in a class in C++?
The problem with a class is that there is the hidden 'this' pointer. So:
class someclass {
public:
void somemeth(void){};
// ... whatever
}
does not have a void function somemeth with void arg list. It is a class
someclass void function with a void arg list.
There are lots of ways to deal with the problem. Typically, if you have some
function that needs to be added on construction time, then just add it to the
constructor argument list. Or you can use friend function (a misspelling of
'fiend function') or many other ways to get things accomplished.
Why don't you demonstrate the exact problem and someone can show you an easy
solution, I imagine.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.