<?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[Problem mit Funktions Pointer]]></title><description><![CDATA[<p>Das cpp File der Klasse zuerst:</p>
<pre><code>CMathFloat::CMathFloat(){

	float(CMathFloat::*ptr)(float);
	string muh = &quot;sin(x)&quot;;
	regFunction(muh,SinX);
}

void CMathFloat::regFunction(string functionName, float (CMathFloat::*ftp)(float)){

	m_regFunctions.insert(make_pair(m_mapIndex,functionName));
	m_pointRegistered.insert(make_pair(functionName,ftp));
	m_mapIndex++;
	//berechne die Funktion

}

float CMathFloat::SinX(float Eingabe){
	const float PI = 3.1415926535;
	Eingabe = Eingabe / 180 * PI;
	float Zahl = (float) sin(Eingabe);

	return Zahl;
}

float CMathFloat::berechneTeilFunktion(){

(... blabla ...)

	endErgebnis = m_pointRegistered[m_regFunctions[i&rsqb;&rsqb;(ergebnis1);

(... blabla ...)

}
</code></pre>
<p>Und der Header:</p>
<pre><code>#ifndef CMATHFLOAT_H_
#define CMATHFLOAT_H_

#include &lt;string&gt;
#include &lt;map&gt;
using namespace std;

class CMathFloat{

private:

	map&lt;int,string&gt; m_regFunctions;
	map&lt;string,float (CMathFloat::*const) (float)&gt; m_pointRegistered;
	int m_mapIndex;
	string m_eingabe;
	float m_ergebnis;
	float addOperation(float Wert1, float Wert2);
	float subOperation(float Wert1, float Wert2);
	float multOperation(float Wert1, float Wert2);
	float transformiereStringToFloat(string Eingabe);
	void entferneLeerstellen();
	int StringToInt(string Eingabe);
	string IntToString(int Wert);
	float berechneErgebnis();
	bool handleFunktionen();
	bool checkFunctions();
	bool checkZeichen(char zeichen);
	float SinX(float Eingabe);
	float berechneTeilFunktion();

public:
	CMathFloat(); 
	~CMathFloat();
	void setEingabe(string eingabeString);
	float starteBerechnung();
	bool checkNumeric();
	bool checkEingabe();
	void regFunction(string functionName, float (CMathFloat::*ftp)(float));

};
</code></pre>
<p>Ok der Code oben funktioniert NICHT. Ich bin mit meinem Latein am Ende und versteh nicht was ich falsch mache.</p>
<p>Zum verstehe: Ich will im Header diverse Funktionen adden die alle das Format<br />
&quot;float Name (float zahl)&quot; haben:<br />
regFunction(muh,SinX);</p>
<p>Die Speichert das Programm in einer map ab. Mit einem Namen und dem Pointer auf die Funktion.<br />
m_regFunctions.insert(make_pair(m_mapIndex,functionName));<br />
m_pointRegistered.insert(make_pair(functionName,ftp));</p>
<p>Später will ich dann die Funktion ganz normal aufrufen über den pointer.<br />
endErgebnis = m_pointRegistered[m_regFunctions[i&rsqb;&rsqb;(ergebnis1);</p>
<p>Kann mir jemand erklären was ich falsch mache?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/212175/problem-mit-funktions-pointer</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 17:24:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/212175.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 May 2008 16:29:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Funktions Pointer on Fri, 02 May 2008 16:29:00 GMT]]></title><description><![CDATA[<p>Das cpp File der Klasse zuerst:</p>
<pre><code>CMathFloat::CMathFloat(){

	float(CMathFloat::*ptr)(float);
	string muh = &quot;sin(x)&quot;;
	regFunction(muh,SinX);
}

void CMathFloat::regFunction(string functionName, float (CMathFloat::*ftp)(float)){

	m_regFunctions.insert(make_pair(m_mapIndex,functionName));
	m_pointRegistered.insert(make_pair(functionName,ftp));
	m_mapIndex++;
	//berechne die Funktion

}

float CMathFloat::SinX(float Eingabe){
	const float PI = 3.1415926535;
	Eingabe = Eingabe / 180 * PI;
	float Zahl = (float) sin(Eingabe);

	return Zahl;
}

float CMathFloat::berechneTeilFunktion(){

(... blabla ...)

	endErgebnis = m_pointRegistered[m_regFunctions[i&rsqb;&rsqb;(ergebnis1);

(... blabla ...)

}
</code></pre>
<p>Und der Header:</p>
<pre><code>#ifndef CMATHFLOAT_H_
#define CMATHFLOAT_H_

#include &lt;string&gt;
#include &lt;map&gt;
using namespace std;

class CMathFloat{

private:

	map&lt;int,string&gt; m_regFunctions;
	map&lt;string,float (CMathFloat::*const) (float)&gt; m_pointRegistered;
	int m_mapIndex;
	string m_eingabe;
	float m_ergebnis;
	float addOperation(float Wert1, float Wert2);
	float subOperation(float Wert1, float Wert2);
	float multOperation(float Wert1, float Wert2);
	float transformiereStringToFloat(string Eingabe);
	void entferneLeerstellen();
	int StringToInt(string Eingabe);
	string IntToString(int Wert);
	float berechneErgebnis();
	bool handleFunktionen();
	bool checkFunctions();
	bool checkZeichen(char zeichen);
	float SinX(float Eingabe);
	float berechneTeilFunktion();

public:
	CMathFloat(); 
	~CMathFloat();
	void setEingabe(string eingabeString);
	float starteBerechnung();
	bool checkNumeric();
	bool checkEingabe();
	void regFunction(string functionName, float (CMathFloat::*ftp)(float));

};
</code></pre>
<p>Ok der Code oben funktioniert NICHT. Ich bin mit meinem Latein am Ende und versteh nicht was ich falsch mache.</p>
<p>Zum verstehe: Ich will im Header diverse Funktionen adden die alle das Format<br />
&quot;float Name (float zahl)&quot; haben:<br />
regFunction(muh,SinX);</p>
<p>Die Speichert das Programm in einer map ab. Mit einem Namen und dem Pointer auf die Funktion.<br />
m_regFunctions.insert(make_pair(m_mapIndex,functionName));<br />
m_pointRegistered.insert(make_pair(functionName,ftp));</p>
<p>Später will ich dann die Funktion ganz normal aufrufen über den pointer.<br />
endErgebnis = m_pointRegistered[m_regFunctions[i&rsqb;&rsqb;(ergebnis1);</p>
<p>Kann mir jemand erklären was ich falsch mache?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1502201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502201</guid><dc:creator><![CDATA[abzy]]></dc:creator><pubDate>Fri, 02 May 2008 16:29:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Pointer on Fri, 02 May 2008 19:01:52 GMT]]></title><description><![CDATA[<p>&quot;Geht nicht&quot; ist keine Fehlerbeschreibung. Weiters wäre es guter Ton, ein (bis auf das Thema der Frage) lauffähiges Minimalbeispiel zu zeigen.</p>
<p>Methodenpointer funktionieren so:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;string&gt;

class foo_t {

public:
	typedef float ( foo_t::*method_ptr )( float );

private:
	typedef std::map&lt; std::string, method_ptr &gt; method_map_t;
	method_map_t method_map;

public:
	void register_method( const std::string &amp;name, method_ptr method )
	{
		method_map.insert( std::make_pair( name, method ) );
	}

	float bar( float f )
	{
		std::cout &lt;&lt; &quot;foo_t::bar( )&quot; &lt;&lt; std::endl;
		return 0.;
	}

	void doit( const std::string &amp;name )
	{
		method_map_t::iterator i = method_map.find( name );

		if( i != method_map.end( ) ) {

			( this-&gt;*( i-&gt;second ) )( 0. );
		}
	}
};

int main( )
{
	foo_t foo;
	foo.register_method( &quot;bar&quot;, &amp;foo_t::bar );
	foo.doit( &quot;bar&quot; );
}
</code></pre>
<p>cheers, Swordfish</p>
<p>PS: Darüber gibt's AFAIR nen ziemlich guten Artikel auf CodeProject.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1502269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502269</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 May 2008 19:01:52 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Pointer on Fri, 02 May 2008 19:14:13 GMT]]></title><description><![CDATA[<p>Danke für die Antwort! Werd das gleich probieren</p>
<blockquote>
<p>&quot;Geht nicht&quot; ist keine Fehlerbeschreibung. Weiters wäre es guter Ton, ein (bis auf das Thema der Frage) lauffähiges Minimalbeispiel zu zeigen.</p>
</blockquote>
<p>Werd es nächstes mal besser schreiben. Sorry</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1502277</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502277</guid><dc:creator><![CDATA[abzy]]></dc:creator><pubDate>Fri, 02 May 2008 19:14:13 GMT</pubDate></item></channel></rss>