03-25-04 05:43 PM
Elias Athanasopoulos wrote:
>
> Hello!
>
> Consider I have a Foo class, which ctor's takes as an argument a pointer
> to function, i.e.:
>
> Foo *foo = new Foo(bar);
>
> Where:
>
> int bar(int);
>
> bar() will eventually get called somewhen inside Foo (it maybe called N
> times).
>
> Now, I want to grab the pointer of Foo's instance (i.e. the 'this'
> pointer) which called bar(), from inside bar(), when that happens.
>
> (I can't pass the pointer in bar() as an argument because Foo's
> implementation is third party.)
>
> I don't mind about portability. I would be happy if I find a way to do
> this on Linux/ix86/gcc.
>
> I tried using the GNU backtrace() extension with no luck. Any hints?
"Foo" is badly designed... contact the author to add an extra-parameter
to the callback, like this:
typedef int callback (int param, void *extrapar);
extern void Foo (callback cbfun, void *extrapar);
typedef struct {
..
} extra_data_for_callback;
int mycallback (int param, void *extrapar)
{
extra_data_for_callback edp = extrapar;
/* do anything with extrapar */
}
main ()
{
extra_data_for_callback ed;
Foo (my_callback, &ed);
}
Note: this is a well know standard technic
should no cause problem to extend Foo this way
[ Post a follow-up to this message ]
|