RE: [Dev-C++] Static members for callbacks
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-07-27 03:58:16
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Abhijit Shylanath
> Sent: Friday, July 26, 2002 11:08 PM
> To: Dev-C++ Mailing List
> Subject: [Dev-C++] Static members for callbacks
>
>
> [... back to right now...]
>
> Okay... putting eleventeen and twenty kazillion together...
> it seems you
> cannot callback to non-static member functions (i.e., you
> cannot have a
> function pointer pointing to a non-static method).
Ok.. It seems i confused subjects. I was thinking that we were talking
about some graphics classes but anyway i am reading like crazy these
days C++ and .NET and there may be some lost clusters somewhere. :)
You can have a function pointer to point to some member functions. But a
non-static member function is not a regular function, that's why we use
special-kind of pointers (a static function on the other hand is a
regular function).
#include <iostream>
int main()
{
class A
{
public:
void something() { std::cout<<"Hello, new world!\n"; }
}a;
void (A::*pf)()=&A::something;
(a.*pf)();
}
> I tried creating a class to test this, and I discovered that
> it's true...
> why?
>
> I tried callback = this->internal, testclass::internal,
> this::internal...
> yup, I got pret-ty desparate.
>
> I also tried casting the method, using type-casting
> (C-style), static_cast
> and dynamic_cast to a pointer, but it doesn't work. I get an
> error about
> converting to a pointer and compilation stops.
>
> [... back to the day I first rode a bike... hey, it's *my* post.]
Well if i understood well your problem was that you did not know how to
define a pointer to member function. Tell me if your problem was solved.
Keep coding,
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|