<?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[Funktionspointer (Boost)]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein Problem mit meinem EventManager. Schnell gesagt: Der EventManager prüft ob eine Taste gedrückt wurde. Wird eine bestimmte Taste gedrückt, soll eine Funktion ausgeführt werden. Um das alles etwas dynamischer zu machen, möchte ich eine &quot;Registerfunktion&quot; haben. Am Ende möchte ich das tun können:</p>
<pre><code class="language-cpp">void TasteA() { std::cout&lt;&lt;&quot;Sie haben A gedrueckt&quot;; }
EventManager Manager;
Manager.RegisterEvent( boost::bind( TasteA ), //Funktion die ausgeführt werden soll...
                       65 ); //... wenn die Taste 'A' (ASCII: 65) gedrückt wurde
</code></pre>
<p>(Code aus dem Kopf getippt, also nur ein Beispiel).</p>
<p>Im Grunde ganz easy, allerdings habe ich kaum Erfahrung mit der Verwendung von boost::function. In meinem Kopf habe ich es mir so gedacht:</p>
<pre><code class="language-cpp">class EventManager : boost::noncopyable
{
	private:
		template &lt;typename FuncSignature&gt;
		std::map&lt; boost::function&lt;FuncSignature (void)&gt;, const int &gt; m_EventMap;
		void CheckIfKeyPressed( ); //Endlosschleife wo geprüft wird ob die Tastatureingabe gleich &quot;ASCIIKeyCode&quot; ist. Falls ja, rufe Funktionsptr auf

	public:
		template &lt;typename FuncSignature&gt;
		void RegisterEvent(  boost::function&lt;FuncSignature (void)&gt; FuncPtr, const int ASCIIKeyCode )
		{
		}
};
</code></pre>
<p>Natürlich geht das mit dem Template und der Membermap nicht. Allerdings weiß ich nicht wie ich das machen soll. Achja; Man soll natürlich Funktionen mit beliebigen Funktionssignaturen übergeben können, aber das kann man ja in aller Regel mit <em>boost::bind</em> machen, richtig?</p>
<p>Nochmal zusammengefasst und kurz gesagt:<br />
Ich übergebe der Registerfunktion eine Funktion, die aufgerufen werden soll, wenn Taste XYZ gedrückt wird.</p>
<p>Ich hoffe mir kann jemand helfen. Vielen lieben Dank im Voraus Männer! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/292970/funktionspointer-boost</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 14:00:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/292970.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Sep 2011 20:33:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktionspointer (Boost) on Wed, 21 Sep 2011 20:33:07 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein Problem mit meinem EventManager. Schnell gesagt: Der EventManager prüft ob eine Taste gedrückt wurde. Wird eine bestimmte Taste gedrückt, soll eine Funktion ausgeführt werden. Um das alles etwas dynamischer zu machen, möchte ich eine &quot;Registerfunktion&quot; haben. Am Ende möchte ich das tun können:</p>
<pre><code class="language-cpp">void TasteA() { std::cout&lt;&lt;&quot;Sie haben A gedrueckt&quot;; }
EventManager Manager;
Manager.RegisterEvent( boost::bind( TasteA ), //Funktion die ausgeführt werden soll...
                       65 ); //... wenn die Taste 'A' (ASCII: 65) gedrückt wurde
</code></pre>
<p>(Code aus dem Kopf getippt, also nur ein Beispiel).</p>
<p>Im Grunde ganz easy, allerdings habe ich kaum Erfahrung mit der Verwendung von boost::function. In meinem Kopf habe ich es mir so gedacht:</p>
<pre><code class="language-cpp">class EventManager : boost::noncopyable
{
	private:
		template &lt;typename FuncSignature&gt;
		std::map&lt; boost::function&lt;FuncSignature (void)&gt;, const int &gt; m_EventMap;
		void CheckIfKeyPressed( ); //Endlosschleife wo geprüft wird ob die Tastatureingabe gleich &quot;ASCIIKeyCode&quot; ist. Falls ja, rufe Funktionsptr auf

	public:
		template &lt;typename FuncSignature&gt;
		void RegisterEvent(  boost::function&lt;FuncSignature (void)&gt; FuncPtr, const int ASCIIKeyCode )
		{
		}
};
</code></pre>
<p>Natürlich geht das mit dem Template und der Membermap nicht. Allerdings weiß ich nicht wie ich das machen soll. Achja; Man soll natürlich Funktionen mit beliebigen Funktionssignaturen übergeben können, aber das kann man ja in aller Regel mit <em>boost::bind</em> machen, richtig?</p>
<p>Nochmal zusammengefasst und kurz gesagt:<br />
Ich übergebe der Registerfunktion eine Funktion, die aufgerufen werden soll, wenn Taste XYZ gedrückt wird.</p>
<p>Ich hoffe mir kann jemand helfen. Vielen lieben Dank im Voraus Männer! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2122270</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2122270</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 21 Sep 2011 20:33:07 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer (Boost) on Wed, 21 Sep 2011 20:39:45 GMT]]></title><description><![CDATA[<p>Sorry wegen dem Doppelpost, aber so finde ich es übersichtlicher:<br />
Ich habe mir nun überlegt das es ja im Prinzip reichen würde, wenn die Funktionssignatur nur einen <em>void</em> als Rückgabewert hätte. Also so:</p>
<pre><code class="language-cpp">class EventManager : boost::noncopyable
{
	private:
		std::map&lt; boost::function&lt;void (void)&gt;, const int &gt; m_EventMap;

		std::vector&lt; std::vector&lt; Chat::Conversation &gt; &gt; &amp;m_Buffer;
		std::vector&lt; std::vector&lt; Chat::Conversation &gt; &gt;::const_iterator m_GlobalIt;

		void CheckIfKeyPressed( );

	public:
		EventManager( std::vector&lt; std::vector&lt; Chat::Conversation &gt; &gt; &amp;Buffer );

		void RegisterEvent(  boost::function&lt;void (void)&gt; FuncPtr, const int ASCIIKeyCode )
		{
		}
};
</code></pre>
<p>Würde im Grunde doch auch schon funktionieren, oder? Allerdings wäre man dann ja so weit eingeschränkt, dass man nur <em>void</em>-Funktionen registrieren kann.</p>
<p>Bitte um Rat und Verbesserungsvorschläge! Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2122271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2122271</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 21 Sep 2011 20:39:45 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer (Boost) on Wed, 21 Sep 2011 20:39:53 GMT]]></title><description><![CDATA[<p>Kann es ein, daß du bei der map-Definition Schlüssel und Wert vertauscht hast? Der erste Parameter (bei dir boost::function&lt;...&gt;) wird als Suchschlüssel verwendet und braucht deshalb eine Kleiner-Beziehung, der zweite Parameter (const int - btw, das const ist dort überflüssig) ist der zugeordnete Wert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2122272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2122272</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 21 Sep 2011 20:39:53 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer (Boost) on Wed, 21 Sep 2011 20:49:23 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Kann es ein, daß du bei der map-Definition Schlüssel und Wert vertauscht hast? Der erste Parameter (bei dir boost::function&lt;...&gt;) wird als Suchschlüssel verwendet und braucht deshalb eine Kleiner-Beziehung, der zweite Parameter (const int - btw, das const ist dort überflüssig) ist der zugeordnete Wert.</p>
</blockquote>
<p>Hey CStoll,<br />
danke erstmal für die Antwort! Ja, du hast Recht. Muss mich irgendwie vertan haben, entschuldigung. So nun also:</p>
<pre><code class="language-cpp">class EventManager : boost::noncopyable
{
	private:
		std::vector&lt; std::pair&lt;boost::function&lt;void (void)&gt;, char &gt; &gt; m_EventMap;

		void CheckIfKeyPressed( );

	public:
		void RegisterEvent(  boost::function&lt;void (void)&gt; FuncPtr, char ASCIIKeyCode )
		{
			m_EventMap = std::make_pair( FuncPtr, ASCIIKeyCode );
		}
};
</code></pre>
<p>//EDIT: Code ist immer noch nicht richtig, wegen dem std::vector&lt;&gt;, allerdings geht's ja auch erstmal nur um die Grundidee.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2122273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2122273</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 21 Sep 2011 20:49:23 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer (Boost) on Wed, 21 Sep 2011 20:57:29 GMT]]></title><description><![CDATA[<p>Was spricht denn gegen eine map&lt;char, function&gt;? Schließlich willst du zu einer vorgegebenen Taste die passende Funktion ermitteln.</p>
<p>Ansonsten: Was genau ist eigentlich dein Problem?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2122276</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2122276</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 21 Sep 2011 20:57:29 GMT</pubDate></item><item><title><![CDATA[Reply to Funktionspointer (Boost) on Wed, 21 Sep 2011 21:28:35 GMT]]></title><description><![CDATA[<p>Hey,<br />
funktioniert jetzt. Trotzdem danke für deine Hilfe!</p>
<p>Nächtle <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2122282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2122282</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 21 Sep 2011 21:28:35 GMT</pubDate></item></channel></rss>