<?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[Virtuelle Funktion -]]></title><description><![CDATA[<p>Hallo <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>
<p>Ich versuche grade eine Klasse zu erstellen, die eine virtuelle Methode hat, die von klasse zu klasse unterschiedlich sein soll.</p>
<p>Es geht um einen Komando Aufruf. Ein vector von &lt;CMD_Interface&gt; soll nach einem string durchsucht werden un bei Fund, die virtuelle Funktion m_method() ausführen, die je nach Komando anders ist.</p>
<p>ich bekomme jetzt folgenden Fehler:</p>
<pre><code>error C2633: 'CMD_Interface': 'inline' ist die einzig zulässige Speicherklasse für Konstruktoren
</code></pre>
<p>meine Klassen sehen so aus:</p>
<pre><code>class CMD_Interface				//cmd_interface.h
{
	public:
		 CMD_Interface(string* command);
		~CMD_Interface();

		bool			execute_if_match(string* str);

	private:
		string			m_cmd;
		virtual void	m_method(vector&lt;string&gt;* pstrings) = 0;
};
</code></pre>
<pre><code>#include &quot;cmd_interface.h&quot;				//	cmd_interface.cpp
#include &lt;sstream&gt;

CMD_Interface ::	CMD_Interface(string* command)
{
	m_cmd		= *command;
}
CMD_Interface ::	~CMD_Interface(){}

bool		CMD_Interface ::	execute_if_match(string* str)
{
	string			buffer;
	stringstream	sstream;
	vector&lt;string&gt;	token;

	sstream		&lt;&lt;	*str; 
	while(sstream &gt;&gt; buffer)	token.push_back(buffer);

	if(token.at(0) == m_cmd)
	{
		stringstream	temp;
		int				value;
		temp &lt;&lt; token.at(1);
		temp &gt;&gt; value;
		m_method(&amp;token);
		return true;
	}
	return false;
}
</code></pre>
<pre><code>class cmd_hello : CMD_Interface			//cmd_list.h
{
	private:
		void	m_method(vector&lt;string&gt;* pstrings)
		{
			cout &lt;&lt; &quot;hello&quot;;
		};
};
</code></pre>
<p>was mag er daran nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/318780/virtuelle-funktion</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Jul 2026 15:03:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318780.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 26 Jul 2013 08:23:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:23:56 GMT]]></title><description><![CDATA[<p>Hallo <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>
<p>Ich versuche grade eine Klasse zu erstellen, die eine virtuelle Methode hat, die von klasse zu klasse unterschiedlich sein soll.</p>
<p>Es geht um einen Komando Aufruf. Ein vector von &lt;CMD_Interface&gt; soll nach einem string durchsucht werden un bei Fund, die virtuelle Funktion m_method() ausführen, die je nach Komando anders ist.</p>
<p>ich bekomme jetzt folgenden Fehler:</p>
<pre><code>error C2633: 'CMD_Interface': 'inline' ist die einzig zulässige Speicherklasse für Konstruktoren
</code></pre>
<p>meine Klassen sehen so aus:</p>
<pre><code>class CMD_Interface				//cmd_interface.h
{
	public:
		 CMD_Interface(string* command);
		~CMD_Interface();

		bool			execute_if_match(string* str);

	private:
		string			m_cmd;
		virtual void	m_method(vector&lt;string&gt;* pstrings) = 0;
};
</code></pre>
<pre><code>#include &quot;cmd_interface.h&quot;				//	cmd_interface.cpp
#include &lt;sstream&gt;

CMD_Interface ::	CMD_Interface(string* command)
{
	m_cmd		= *command;
}
CMD_Interface ::	~CMD_Interface(){}

bool		CMD_Interface ::	execute_if_match(string* str)
{
	string			buffer;
	stringstream	sstream;
	vector&lt;string&gt;	token;

	sstream		&lt;&lt;	*str; 
	while(sstream &gt;&gt; buffer)	token.push_back(buffer);

	if(token.at(0) == m_cmd)
	{
		stringstream	temp;
		int				value;
		temp &lt;&lt; token.at(1);
		temp &gt;&gt; value;
		m_method(&amp;token);
		return true;
	}
	return false;
}
</code></pre>
<pre><code>class cmd_hello : CMD_Interface			//cmd_list.h
{
	private:
		void	m_method(vector&lt;string&gt;* pstrings)
		{
			cout &lt;&lt; &quot;hello&quot;;
		};
};
</code></pre>
<p>was mag er daran nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341398</guid><dc:creator><![CDATA[cl90]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:23:56 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:27:13 GMT]]></title><description><![CDATA[<p>naja zunächst mal vererbst du private methoden nicht. die müssten public sein.</p>
<p>und wenn du rein virtuelle methoden überschreiben willst, müssen die neuen versionen auch virual sein (aber eben nicht pure virutal).</p>
<p>und ich bin mir nicht ganz sicher ob die private vererbung hier gewünscht ist (kann es nicht beurteilen anhand der bislang gegebenen informationen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341399</guid><dc:creator><![CDATA[referator]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:27:13 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:28:02 GMT]]></title><description><![CDATA[<p>edit zum ersten satz:<br />
die müssten public ODER PROTECTED sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341400</guid><dc:creator><![CDATA[referator]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:28:02 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:32:27 GMT]]></title><description><![CDATA[<p>Also, das ist schon mal gar nicht möglich - man kann keinen upcast auf eine private Basisklasse machen. Die Fehlermeldung die du bekommst resultiert auch gar nicht aus dem gezeigten Code (abgetippt?).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341401</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:32:27 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:38:35 GMT]]></title><description><![CDATA[<p>ok das mit procted/Public macht Sinn.</p>
<p>Ich beschreibe mal genauer was ich vorhabe:<br />
Ich habe eine Klasse Console, die einen Vector von commands in form von klassen hat.<br />
eine funktion search() führt jetzt für jeden Eintrag des vectors &quot;execute_if_match(string* str)&quot; aus, bis einer true zurückgibt.</p>
<p>execute_if_match() wird dann ja von der entsprechenden klasse ausgeführt. wie z.b. nach eingabe von: &quot;set_com_port&quot;<br />
wird search() die klasse cmd_set_com finden, und die von ihr implementierten m_method() ausführen.</p>
<p>Ich möchte letztendlich eine schöne Console bauen, die commands hübsch verwaltet, ohne hässliche case tabellen zu haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341402</guid><dc:creator><![CDATA[cl90]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:38:35 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:45:51 GMT]]></title><description><![CDATA[<p>referator schrieb:</p>
<blockquote>
<p>naja zunächst mal vererbst du private methoden nicht. die müssten public sein.</p>
</blockquote>
<p>Selbstverständlich können die auch private sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341406</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:45:51 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 08:48:47 GMT]]></title><description><![CDATA[<p>ich hatte sie auf private gesetzt da ich sie nur innerhalb der klasse CMD_interface aufrufen wollte.</p>
<p>Wenn ich jetzt die einzelnen Kommandoklassen von dem CMD_interface ableite, schreib ich dann private, oder gar nichts? da ich ja eigentlich die CMD_interface klasse haben mag, nur mit spezieller m_method().</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341407</guid><dc:creator><![CDATA[cl90]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:48:47 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 09:04:19 GMT]]></title><description><![CDATA[<p>cl90 schrieb:</p>
<blockquote>
<p>ich hatte sie auf private gesetzt da ich sie nur innerhalb der klasse CMD_interface aufrufen wollte.</p>
</blockquote>
<p>So kann man das auch machen.</p>
<p>cl90 schrieb:</p>
<blockquote>
<p>Wenn ich jetzt die einzelnen Kommandoklassen von dem CMD_interface ableite, schreib ich dann private, oder gar nichts?</p>
</blockquote>
<p>Gar nicht ist wie private. Du willst aber wohl public.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341413</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 26 Jul 2013 09:04:19 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 09:34:43 GMT]]></title><description><![CDATA[<p>Oh ich glaube grade mein ansatz war einfach falsch.</p>
<p>ich denke stichwort Strategy wäre hier richtiger.<br />
Ich werd mich mal einlesen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341418</guid><dc:creator><![CDATA[cl90]]></dc:creator><pubDate>Fri, 26 Jul 2013 09:34:43 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 10:32:07 GMT]]></title><description><![CDATA[<p>Und wenn du gerade dabei bist, dein Design zu überdenken:<br />
Warum übergibst du überall Zeiger auf Objekte, statt sie per-value oder per-reference zu übergeben? Zeiger können da Sinn machen, wo die Parameter optional sind und <code>nullptr</code> eine gültige Option sind. Allerdings scheint das bei dir nicht der Fall zu sein, du prüfst nirgendwo, ob deine Zeiger überhaupt gültig sind.</p>
<p>Edit:<br />
Und poste bitte den vollständigen Quelltext. In deiner Header Datei wird nirgends <code>string</code> inkludiert, das sollte dein Compiler schon melden. Und du benutzt irgendwo ein <code>using namespace std;</code> , das gehört da sicher auch nicht hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341432</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Fri, 26 Jul 2013 10:32:07 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 10:30:56 GMT]]></title><description><![CDATA[<p>Das mit den pointern hab ich heute von einem Kollegen gehört.<br />
Ich werde mir in zukunft die Referenzen angewöhnen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341434</guid><dc:creator><![CDATA[cl90]]></dc:creator><pubDate>Fri, 26 Jul 2013 10:30:56 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 10:32:02 GMT]]></title><description><![CDATA[<p>Du scheinst das System mit public, protected, private nicht ganz zu verstehen.<br />
public ist von überall zugreifbar. Da man die Werte ändern kann, sollte man Zugriffe über Methoden gestalten, um auf fehlerhafte Werte reagieren zu können.<br />
private ist vor ALLEM versteckt, auch vor abgeleiteten Klassen.<br />
proteted ist nach außen versteckt, aber abgeleitete Klassen können darauf ganz normal zugreifen.</p>
<p>Wo man bei einer einzelnen Klasse private verwendet, gehört bei Vererbten oft (aber nicht immer) protected hin.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341435</guid><dc:creator><![CDATA[Marthog]]></dc:creator><pubDate>Fri, 26 Jul 2013 10:32:02 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 10:56:47 GMT]]></title><description><![CDATA[<p>Marthog schrieb:</p>
<blockquote>
<p>Du scheinst das System mit public, protected, private nicht ganz zu verstehen.<br />
public ist von überall zugreifbar. Da man die Werte ändern kann, sollte man Zugriffe über Methoden gestalten, um auf fehlerhafte Werte reagieren zu können.<br />
private ist vor ALLEM versteckt, auch vor abgeleiteten Klassen.<br />
proteted ist nach außen versteckt, aber abgeleitete Klassen können darauf ganz normal zugreifen.</p>
<p>Wo man bei einer einzelnen Klasse private verwendet, gehört bei Vererbten oft (aber nicht immer) protected hin.</p>
</blockquote>
<p>und wie schließt du da drauf das ich es nicht verstanden habe?<br />
Ich nutze das genau so. mit get und set variablen, memberfunktionen und bei vererbungen gebe ich protected.<br />
trozdem danke, vlt. liest es jemand der es noch nicht wusste</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341447</guid><dc:creator><![CDATA[cl90]]></dc:creator><pubDate>Fri, 26 Jul 2013 10:56:47 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 10:58:02 GMT]]></title><description><![CDATA[<p>Marthog schrieb:</p>
<blockquote>
<p>Wo man bei einer einzelnen Klasse private verwendet, gehört bei Vererbten oft (aber nicht immer) protected hin.</p>
</blockquote>
<p>Falsch, erstmal sollte alles private sind. Nur bei echt guten Gründen machst du etwas protected. Ein guter Grund ist zum Beispiel das Template-Method-Pattern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341448</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341448</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 26 Jul 2013 10:58:02 GMT</pubDate></item><item><title><![CDATA[Reply to Virtuelle Funktion - on Fri, 26 Jul 2013 15:35:16 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Ein guter Grund ist zum Beispiel das Template-Method-Pattern.</p>
</blockquote>
<p>Noe, ist es nicht.</p>
<pre><code>#include &lt;iostream&gt;

struct Base
{
    void f() const
    {
        pre_f();
        std::cout &lt;&lt; &quot;f() stuff\n&quot;;
        post_f();
    }

    virtual ~Base() {}

private:
    virtual void pre_f() const = 0;
    virtual void post_f() const = 0;
};

struct Derived : Base
{
private:
    virtual void pre_f() const override
    {
        std::cout &lt;&lt; &quot;pre f() stuff\n&quot;;
    }

    virtual void post_f() const override
    {
        std::cout &lt;&lt; &quot;post f() stuff\n&quot;;
    }
};

int main()
{
    Derived d;
    d.f();
}
</code></pre>
<p><a href="https://ideone.com/UZ1Fid" rel="nofollow">https://ideone.com/UZ1Fid</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341519</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Fri, 26 Jul 2013 15:35:16 GMT</pubDate></item></channel></rss>