Zeiger auf Klassenfunktion?
-
Suchfunktion hab ich benutzt, aber leider wurde meine Frage dadurch nicht geklaert.
Folgendes Problem:Ich schreibe mir momentan eine DLL, die auch eine Klasse fuers Multithreading enthaelt.
Das hier ist ein Teil davon:/* FILE : dtThread.h Purpose : A class for Multithreading Author : Scorcher (C) 2005 Wizard Soft. All Rights reserved. This file may be redistributed under the Terms of DieselEngine's License. */ #ifndef __DTHREAD_H__ #define __DTHREAD_H__ #include "dtMacros.h" #include "dtTypes.h" #if defined(_MSC_VER) # pragma warning (disable:4511 4275 4512 4251 4702) #endif // _MSC_VER #define BOOST_SIGNALS_STATIC_LINK #include <boost/signal.hpp> #undef BOOST_SIGNALS_STATIC_LINK #ifdef WIN32 typedef HANDLE dtThreadHandle; #elif _UNIXLIKE_ typedef pthread dtThreadHandle; #endif /* WIN32 */ #ifdef WIN32 typedef CRITICAL_SECTION dtMutexSection; #endif /** @typedef dtThreadHandle * @brief This is a Handle to the created thread. * @ingroup g_dieseltool */ /** @brief Type for the ThreadFunction * @ingroup g_dieseltool */ typedef boost::signal<void ()> ThreadFunc; /** @brief enum for the flags * @ingroup g_dieseltool */ enum dtThreadFlag { /** @brief The Thread will run immediatly after creation **/ dtNORMAL = 0x00000000, /** @brief The Thread will not run unitl you call dtThread::ResumeThread(). */ dtSUSPENDED = 0x00000004, }; /** @brief Mutexes ensure that you don't use data which is currently in use. * @ingroup g_dieseltool */ class DIESELTOOLEXPORT dtMutex { public: /** @brief Constructor **/ dtMutex(); /** @brief Deconstructor **/ ~dtMutex(); /** @brief Notify class that you enter a critical section. */ void EnterSection(); /** @brief Notify class that you leaved the section. */ void LeaveSection(); /** @brief Let's the Thread wait until you call dtMutex::Notify(); */ void Wait(); /** @brief Cancelles a wait-operation. */ void Notify(); /** @brief Tries to enter the Critical Section. */ bool TryEnterSection(); protected: // Not copyable void operator=(const dtMutex& copy); dtMutex( const dtMutex& copy); private: HANDLE m_event; dtMutexSection m_critical; }; /** @brief This class can do multithreading for you. * @ingroup g_dieseltool */ class DIESELTOOLEXPORT dtThread { public: /** @brief Constructor **/ dtThread(); /** @brief Deconstructor */ ~dtThread(); /** @brief Creates the Thread. * * @return true on success, false if the new thread cannot be created. */ bool CreateThread( DWORD flag = dtNORMAL ); /** @brief Connects a method to the Class as Callback. */ void Connect( const ThreadFunc::slot_type& slot ); /** @brief Resumes a suspended Thread */ void ResumeThread(); /** @brief Suspends a Thread */ void SuspendThread(); /** @brief Stops a Thread */ void ExitThread(); /** @brief Returns the Thread's Exit code. * @return The value set with dtThread::SetExitCode() or 0. */ DWORD GetExitCode(); /** @brief Sets the Exit code, but does not exit the Thread. * @param value The code the Thread will Exit with */ void SetExitCode( DWORD value ); /** @brief Reports if a Thread is running */ bool IsRunning(); /** @brief Returns the Handle for this Thread */ dtThreadHandle GetHandle(); private: dtThreadHandle m_handle; ThreadFunc m_callback; bool m_running; DWORD m_retval; protected: friend DWORD __stdcall theThread( dtThread* instance ); }; #if defined(_MSC_VER) # pragma warning (default: 4511 4275 4512 4251 4702) #endif // _MSC_VER #endif /* __DTHREAD_H__ */Das "Problem" ist die Funktion "void Connect( const ThreadFunc::slot_type& slot );". Ich schaff es einfach nicht der Funktion einen Zeiger auf eine andere Funktion zu uebergeben, die Mitglied einer Klasse ist. Momentan hab ich mir (wie man erkennen kann) mit der Boost-Lib beholfen, aber die ist leider sehr groß und verursacht viele Warnungen.

Die uergebene Funktion soll naemlich dann aufgerufen werden, wenn der Thread mit seiner Runde dran ist.
Ueber etwas Hilfe wuerde ich mich wahnsinnig freuen, weil irgendwie muessen die von Boost es ja auch geschafft haben, aber ich blick bei deren Hyroglyphen-Code net durch :D. Ich steh etwas auf dem Schlauch.
Danke fuer eure Hilfe im voraus.
rya.
-
Das gleiche wie hier, nur ohne Templates:
http://c-plusplus.net/forum/viewtopic-var-p-is-1235139.html#1235139