[Dev-C++] Static members for callbacks
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2002-07-26 20:08:52
|
[Today...] > That static-members issue of yours confused me. [...much, much long ago, in a land far, far away...] > Another rule > to tag on > to using static members for > callbacks. [... same land, somewhere between the two...] > I am facing a tricky problem. I have defined a class, > in which there are few funtions written for > implementing multithreading. I have a funtion named > "createThreads_()", which creates few threads. There > is another function declared in the class, "DWORD > WINAPI threadEntry_(LPVOID)". This function pointer > has been passed in the CREATETHREAD(..) call, which is > being raised as an error in VC++ compier. > It gives the error like, blah > If I use any external function Thread Function(making > it as friend to the class) then compilation is > through, WHICH IS AS EXPECTED. > Similarly, if I make the "threadEntry_(..)" in class > as STATIC and use it in CREATETHREAD(..) call then > also compilation is through. But making STATIC wont > serve my purpose. > I can go ahead with using external function by making > int as friend to the class. [... 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). 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.] |