<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Zeiger auf Klassenfunktion?]]></title><description><![CDATA[<p>Suchfunktion hab ich benutzt, aber leider wurde meine Frage dadurch nicht geklaert.<br />
Folgendes Problem:</p>
<p>Ich schreibe mir momentan eine DLL, die auch eine Klasse fuers Multithreading enthaelt.<br />
Das hier ist ein Teil davon:</p>
<pre><code class="language-cpp">/*
    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 &quot;dtMacros.h&quot;
#include &quot;dtTypes.h&quot;

#if defined(_MSC_VER)
#   pragma warning (disable:4511 4275 4512 4251 4702)
#endif // _MSC_VER

#define BOOST_SIGNALS_STATIC_LINK
#include &lt;boost/signal.hpp&gt;
#undef BOOST_SIGNALS_STATIC_LINK

#ifdef WIN32
    typedef HANDLE dtThreadHandle;
#elif _UNIXLIKE_
    typedef pthread dtThreadHandle;
#endif /* WIN32 */

#ifdef WIN32 
    typedef CRITICAL_SECTION dtMutexSection;
#endif

/** <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30982">@typedef</a> dtThreadHandle
  * @brief This is a Handle to the created thread.
  * @ingroup g_dieseltool
  */

/** @brief Type for the ThreadFunction 
  * @ingroup g_dieseltool
  */
typedef boost::signal&lt;void ()&gt; 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&amp; copy);
    dtMutex( const dtMutex&amp; 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&amp; 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__ */
</code></pre>
<p>Das &quot;Problem&quot; ist die Funktion &quot;void Connect( const ThreadFunc::slot_type&amp; slot );&quot;. Ich schaff es einfach nicht der Funktion einen <em>Zeiger auf eine andere Funktion zu uebergeben, die Mitglied einer Klasse ist.</em> Momentan hab ich mir (wie man erkennen kann) mit der Boost-Lib beholfen, aber die ist leider sehr groß und verursacht viele Warnungen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /><br />
Die uergebene Funktion soll naemlich dann aufgerufen werden, wenn der Thread mit seiner Runde dran ist.<br />
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.<br />
Danke fuer eure Hilfe im voraus.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/179948/zeiger-auf-klassenfunktion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 13:08:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/179948.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Apr 2007 21:40:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zeiger auf Klassenfunktion? on Thu, 26 Apr 2007 21:46:51 GMT]]></title><description><![CDATA[<p>Suchfunktion hab ich benutzt, aber leider wurde meine Frage dadurch nicht geklaert.<br />
Folgendes Problem:</p>
<p>Ich schreibe mir momentan eine DLL, die auch eine Klasse fuers Multithreading enthaelt.<br />
Das hier ist ein Teil davon:</p>
<pre><code class="language-cpp">/*
    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 &quot;dtMacros.h&quot;
#include &quot;dtTypes.h&quot;

#if defined(_MSC_VER)
#   pragma warning (disable:4511 4275 4512 4251 4702)
#endif // _MSC_VER

#define BOOST_SIGNALS_STATIC_LINK
#include &lt;boost/signal.hpp&gt;
#undef BOOST_SIGNALS_STATIC_LINK

#ifdef WIN32
    typedef HANDLE dtThreadHandle;
#elif _UNIXLIKE_
    typedef pthread dtThreadHandle;
#endif /* WIN32 */

#ifdef WIN32 
    typedef CRITICAL_SECTION dtMutexSection;
#endif

/** <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30982">@typedef</a> dtThreadHandle
  * @brief This is a Handle to the created thread.
  * @ingroup g_dieseltool
  */

/** @brief Type for the ThreadFunction 
  * @ingroup g_dieseltool
  */
typedef boost::signal&lt;void ()&gt; 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&amp; copy);
    dtMutex( const dtMutex&amp; 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&amp; 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__ */
</code></pre>
<p>Das &quot;Problem&quot; ist die Funktion &quot;void Connect( const ThreadFunc::slot_type&amp; slot );&quot;. Ich schaff es einfach nicht der Funktion einen <em>Zeiger auf eine andere Funktion zu uebergeben, die Mitglied einer Klasse ist.</em> Momentan hab ich mir (wie man erkennen kann) mit der Boost-Lib beholfen, aber die ist leider sehr groß und verursacht viele Warnungen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /><br />
Die uergebene Funktion soll naemlich dann aufgerufen werden, wenn der Thread mit seiner Runde dran ist.<br />
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.<br />
Danke fuer eure Hilfe im voraus.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1274257</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1274257</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 26 Apr 2007 21:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Zeiger auf Klassenfunktion? on Thu, 26 Apr 2007 22:37:39 GMT]]></title><description><![CDATA[<p>Das gleiche wie hier, nur ohne Templates:<br />
<a href="http://c-plusplus.net/forum/viewtopic-var-p-is-1235139.html#1235139" rel="nofollow">http://c-plusplus.net/forum/viewtopic-var-p-is-1235139.html#1235139</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1274279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1274279</guid><dc:creator><![CDATA[audacia]]></dc:creator><pubDate>Thu, 26 Apr 2007 22:37:39 GMT</pubDate></item></channel></rss>