On Aug 10, 10:22 am, Neo <zingafri...@yahoo.comwrote:
On Aug 10, 11:22 am, Ian Collins <ian-n...@hotmail.comwrote:
Neo wrote:
I searched in the groups here but didnt find any post answering my
question. My question is I need the address of the member function in
the same class. Is there anyway to go about it other than making the
func static?
For ex:
class foo {
some_type x
void fa();
----
}
Now in its constructor-
foo::foo() {
x = <adddress_of_fa>;
}
how do I do the above?? I tried &(this->fa) but it says "C++ forbids
taking the address of a bound member function to form a pointer"
class foo {
typedef void (foo::*some_type)();
some_type x;
void fa();
foo() : x(&foo::fa) {}
};
I have a correction-
x needs something of type void(*)() but can I pass the address
void(foo::*)() to it Or should it be a static function only?
The only thing you can use for type void(*)() is a free function
or a static function, with the correct signature.
In C++, the usual solution here would be to replace the
void(*)() with something like:
struct Callback
{
virtual ~Callback() {}
virtual void operator()() const = 0 ;
} ;
and use a Callback const*. If you have access to the sources
where the callback is used, do this. Otherwise, you're sort of
stuck.
Note too that if you pass the pointer to function to a C
function, the function itself has to be `extern "C"'. Which
means that even a static member function can't be used.
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34