<?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[maximum im Array finden]]></title><description><![CDATA[<p>Hallo Leute!</p>
<p>habe bei folgendem programm ein problem!<br />
..dieses soll aus einem array mit schuelernamen und noten den besten in INFORMATIK finden und dieses Element ausgeben!<br />
..Tut es aber nit..es wird immer das selbe element ausgegeben (immer das 3te)..und ich habe absolut keine idee warum..habe schon lange getüftelt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /><br />
..bitte um RAT!<br />
<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>..der quellcode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

//Struktur muss global gesetzt werden, da dise dann im UP auch gebraucht wird
struct SchuelerUndNoten{
	char vname[30];
	char nname[30];
	int info;
	int mathe;
	int phy;
};

//Prototyp
SchuelerUndNoten findbest (SchuelerUndNoten[]);

//Hauptprogramm
void main()
{
//Array &quot;student&quot; vom typ &quot;SchuelerUndNote&quot;
SchuelerUndNoten student[4];

	//Befüllen des Array &quot;student&quot; vom typ &quot;SchuelerUndNote&quot;
	for(int i = 0; i &lt; 4; i++)
		{
			cout &lt;&lt; &quot;Geben Sie den Vormane des Studenten ein: &quot;;
			cin &gt;&gt; student[i].vname;

			cout &lt;&lt; &quot;Geben Sie den Nachname des Studenten ein: &quot;;
			cin &gt;&gt; student[i].nname;

			cout &lt;&lt; &quot;Geben Sie die note in Informatik ein: &quot;;
			cin &gt;&gt; student[i].info;

			cout &lt;&lt; &quot;Geben Sie die note in Mathematik ein: &quot;;
			cin &gt;&gt; student[i].mathe;

			cout &lt;&lt; &quot;Geben Sie die note in Physik ein: &quot;;
			cin &gt;&gt; student[i].phy;
		}

SchuelerUndNoten help;      //Hilfsvariable &quot;help&quot; vom typ &quot;SchuelerUndNote&quot;
help = findbest (student);  /*  ...die funktion &quot;findbest&quot; ermittelt den besten 
                            &quot;student&quot; in info und speicher diese Element des Arrays in &quot;help&quot; */

	//Ausgabe der einzelnen Elemente des in &quot;findbest&quot; gespeicherten &quot;student&quot;
	cout &lt;&lt; &quot;Der beste Student in info...   &quot; &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat den Vorname: &quot; &lt;&lt; help.vname &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat den Nachname: &quot; &lt;&lt; help.nname &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat eine &quot; &lt;&lt; help.info &lt;&lt; &quot; in Info!&quot; &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat eine &quot; &lt;&lt; help.mathe &lt;&lt; &quot; in Mathe!&quot; &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat eine &quot; &lt;&lt; help.phy &lt;&lt; &quot; in Physik!&quot; &lt;&lt; endl;

system(&quot;Pause&quot;);

}

//Unterprogramm
SchuelerUndNoten findbest (SchuelerUndNoten student[4])
{

SchuelerUndNoten bestinfo;

for(int i=0; i &lt; 4; i++)
	{
	if (student[i].info &lt; student[i+1].info)
		{
		bestinfo=student[i];
		}
	}

return bestinfo;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/252809/maximum-im-array-finden</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 04:54:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252809.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Oct 2009 21:07:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 21:11:33 GMT]]></title><description><![CDATA[<p>Hallo Leute!</p>
<p>habe bei folgendem programm ein problem!<br />
..dieses soll aus einem array mit schuelernamen und noten den besten in INFORMATIK finden und dieses Element ausgeben!<br />
..Tut es aber nit..es wird immer das selbe element ausgegeben (immer das 3te)..und ich habe absolut keine idee warum..habe schon lange getüftelt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /><br />
..bitte um RAT!<br />
<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>..der quellcode:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

//Struktur muss global gesetzt werden, da dise dann im UP auch gebraucht wird
struct SchuelerUndNoten{
	char vname[30];
	char nname[30];
	int info;
	int mathe;
	int phy;
};

//Prototyp
SchuelerUndNoten findbest (SchuelerUndNoten[]);

//Hauptprogramm
void main()
{
//Array &quot;student&quot; vom typ &quot;SchuelerUndNote&quot;
SchuelerUndNoten student[4];

	//Befüllen des Array &quot;student&quot; vom typ &quot;SchuelerUndNote&quot;
	for(int i = 0; i &lt; 4; i++)
		{
			cout &lt;&lt; &quot;Geben Sie den Vormane des Studenten ein: &quot;;
			cin &gt;&gt; student[i].vname;

			cout &lt;&lt; &quot;Geben Sie den Nachname des Studenten ein: &quot;;
			cin &gt;&gt; student[i].nname;

			cout &lt;&lt; &quot;Geben Sie die note in Informatik ein: &quot;;
			cin &gt;&gt; student[i].info;

			cout &lt;&lt; &quot;Geben Sie die note in Mathematik ein: &quot;;
			cin &gt;&gt; student[i].mathe;

			cout &lt;&lt; &quot;Geben Sie die note in Physik ein: &quot;;
			cin &gt;&gt; student[i].phy;
		}

SchuelerUndNoten help;      //Hilfsvariable &quot;help&quot; vom typ &quot;SchuelerUndNote&quot;
help = findbest (student);  /*  ...die funktion &quot;findbest&quot; ermittelt den besten 
                            &quot;student&quot; in info und speicher diese Element des Arrays in &quot;help&quot; */

	//Ausgabe der einzelnen Elemente des in &quot;findbest&quot; gespeicherten &quot;student&quot;
	cout &lt;&lt; &quot;Der beste Student in info...   &quot; &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat den Vorname: &quot; &lt;&lt; help.vname &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat den Nachname: &quot; &lt;&lt; help.nname &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat eine &quot; &lt;&lt; help.info &lt;&lt; &quot; in Info!&quot; &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat eine &quot; &lt;&lt; help.mathe &lt;&lt; &quot; in Mathe!&quot; &lt;&lt; endl;

	cout &lt;&lt; &quot;...hat eine &quot; &lt;&lt; help.phy &lt;&lt; &quot; in Physik!&quot; &lt;&lt; endl;

system(&quot;Pause&quot;);

}

//Unterprogramm
SchuelerUndNoten findbest (SchuelerUndNoten student[4])
{

SchuelerUndNoten bestinfo;

for(int i=0; i &lt; 4; i++)
	{
	if (student[i].info &lt; student[i+1].info)
		{
		bestinfo=student[i];
		}
	}

return bestinfo;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1797703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797703</guid><dc:creator><![CDATA[huckleberry]]></dc:creator><pubDate>Sat, 24 Oct 2009 21:11:33 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 21:17:19 GMT]]></title><description><![CDATA[<p>Gut, dass du den Titel geändert hast. Ich habe mir deinen Beitrag nämlich vorher aus Prinzip nicht angeschaut. <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>
<pre><code class="language-cpp">for(int i=0; i &lt; 4; i++) 
    { 
    if (student[i].info &lt; student[i+1].info) 
        { 
        bestinfo=student[i]; 
        } 
    }
</code></pre>
<p>Da stimmt was mit der Logik nicht. Zudem solltest du die Arraygrenzen prüfen, mit <code>student[i+1]</code> bist du bei i == 4 ausserhalb des gültigen Bereichs.</p>
<p>Wie prüft man ein Maximum? Man schaut bei jedem Element, ob es besser als das bisherige Maximum ist. Falls ja, setzt man dieses neu. Am Anfang wählt man für das Maximum einen Wert, der mit Sicherheit schlechter als alles andere ist (oder man prüft das erste Element nicht).</p>
<p>Was du machst, ist einen Studenten mit seinem Vorgänger zu prüfen. Im Vergleich wird der bisherige Wert des Maximums gar nicht berücksichtigt.</p>
<p>Ach ja: Schreibe doch bitte <code>int main()</code> , <code>void main()</code> ist nämlich kein gültiges C++. <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/1797707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797707</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 24 Oct 2009 21:17:19 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 21:25:13 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int best = 0;
for(int i = 1; i &lt; 4; ++i)
    {
    if (student[i].info &lt; student[best].info)
        {
        best = i;
        }
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1797711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797711</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Sat, 24 Oct 2009 21:25:13 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 21:25:45 GMT]]></title><description><![CDATA[<p>da die schlechteste note 6 ist, würde ich da so ran gehn...</p>
<pre><code class="language-cpp">SchuelerUndNoten findbest (SchuelerUndNoten student[4])
{

SchuelerUndNoten bestinfo;
int note = 6;

for(int i=0; i &lt; 4; i++)
{  
    if (student[i].info &lt;= note)
    {  note = student[i].info;
       bestinfo=student[i];
    }
}
return bestinfo;
}
</code></pre>
<p>gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797712</guid><dc:creator><![CDATA[Gustl]]></dc:creator><pubDate>Sat, 24 Oct 2009 21:25:45 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 21:30:37 GMT]]></title><description><![CDATA[<p>Ist das ne Hausaufgabe?<br />
Wenn ja: vor kurzem(letzte Woche?!) gabs schon mal nen Thread, der sich genau darum gedreht hatte...<br />
Falls nicht: Dann bist du wohl der selbe und hattest es schon mal geschafft?!</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797717</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 24 Oct 2009 21:30:37 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 21:56:36 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Gut, dass du den Titel geändert hast. Ich habe mir deinen Beitrag nämlich vorher aus Prinzip nicht angeschaut. <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>
</blockquote>
<p>Nur zum Löschen hab ich ihn angeklickt und dann war er halt doch der Mühe wert. <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="🙂"
    /> Hab sogar die cpp-Tags eingebastelt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797739</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797739</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 24 Oct 2009 21:56:36 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 23:10:03 GMT]]></title><description><![CDATA[<p>Da, bidde:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
#include &lt;vector&gt;
#include &lt;algorithm&gt; // std::sort
#include &lt;string&gt; // std::cin&gt;&gt; overload
#include &lt;conio.h&gt; // ::getch()

struct Name_Product
{
	Name_Product::Name_Product(const std::string &amp;newVname, const std::string &amp;newName,
							   const unsigned int &amp;newProduct):
		vname(newVname),
		nname(newName),
		product(newProduct) { }

	std::string vname, nname;
	unsigned int product;
};

class Schueler
{ 
	public:
		Schueler();
		Schueler(const Schueler &amp;schueler);
		Schueler(const std::string &amp;newVname, const std::string &amp;newNname, 
				 const unsigned char &amp;newInfo, const unsigned char &amp;newMathe,
				 const unsigned char &amp;newPhy);

		const bool operator == (const Schueler &amp;schueler) const;
		const Schueler operator = (const Schueler &amp;schueler) const;

		const unsigned int GetProduct() const;

	public: // Gaaanz gaaanz böse...
		std::string vname; 
		std::string nname; 
		unsigned char info; 
		unsigned char mathe; 
		unsigned char phy; 
}; 

Schueler::Schueler():
	info(NULL),
	mathe(NULL),
	phy(NULL) { }

Schueler::Schueler(const Schueler &amp;schueler):
	vname(schueler.vname),
	nname(schueler.nname),
	info(schueler.info),
	mathe(schueler.mathe),
	phy(schueler.phy) { }

Schueler::Schueler(const std::string &amp;newVname, const std::string &amp;newNname, 
				   const unsigned char &amp;newInfo, const unsigned char &amp;newMathe,
				   const unsigned char &amp;newPhy):
	vname(newVname),
	nname(newNname),
	info(newInfo),
	mathe(newMathe),
	phy(newPhy) { }

const bool Schueler::operator == (const Schueler &amp;schueler) const
{
	if((info == schueler.info)
	 &amp;&amp;(mathe == schueler.mathe)
	 &amp;&amp;(phy == schueler.phy))
		return true;

	else
		return false;
}

const Schueler Schueler::operator = (const Schueler &amp;schueler) const
{
	return ::Schueler(schueler);
}

const unsigned int Schueler::GetProduct() const
{
	return (info + mathe + phy);
}

const Schueler findedenbesten(std::vector&lt;Schueler&gt; &amp;student) ;

void main() 
{ 
	std::vector&lt;Schueler&gt; Student;
	Schueler neuStudent;
	char result(NULL);

	while(result != 'J')
	{
		std::cout&lt;&lt;&quot;Neuen Student anlegen: &quot;&lt;&lt;std::endl;
		std::cout&lt;&lt;&quot;Vorname: &quot;;
		std::cin&gt;&gt; neuStudent.vname;
		std::cout&lt;&lt;&quot;Nachname: &quot;;
		std::cin&gt;&gt; neuStudent.nname;
		std::cout&lt;&lt;&quot;Informatiknote (1-6): &quot;;
		std::cin&gt;&gt; neuStudent.info;
		std::cout&lt;&lt;&quot;Mathematiknote (1-6): &quot;;
		std::cin&gt;&gt; neuStudent.mathe;
		std::cout&lt;&lt;&quot;Phsyiknote (1-6): &quot;;
		std::cin&gt;&gt; neuStudent.phy;

		Student.push_back(neuStudent);

		std::cout&lt;&lt;&quot;Auswerten? (J/N) &quot;;
		std::cin&gt;&gt; result;

		if(result == 'J')
			std::cout&lt;&lt;&quot;=========================&quot;&lt;&lt;std::endl;
	}

	Schueler auswertung(findedenbesten(Student));

	if(auswertung.vname == &quot;undefined&quot;)
		std::cout&lt;&lt;&quot;Die Datenbank konnte nicht ausgewertet werden... &quot;&lt;&lt;std::endl;
	else
	{
		std::cout&lt;&lt; &quot;Der beste Student in info... &quot;&lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;...hat den Vorname: &quot; &lt;&lt; auswertung.vname &lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;...hat den Nachname: &quot; &lt;&lt; auswertung.nname &lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;...hat eine &quot; &lt;&lt; auswertung.info &lt;&lt; &quot; in Info!&quot; &lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;...hat eine &quot; &lt;&lt; auswertung.mathe &lt;&lt; &quot; in Mathe!&quot; &lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;...hat eine &quot; &lt;&lt; auswertung.phy &lt;&lt; &quot; in Physik!&quot; &lt;&lt;std::endl; 
	}

	getch(); // Bitte in die Konsolen FAQ schauen!
} 

const Schueler findedenbesten(std::vector&lt;Schueler&gt; &amp;student) 
{
	std::vector&lt;Schueler&gt;::iterator it(student.begin()), it2(student.begin());
	std::vector&lt;Name_Product&gt; newStudent;
	std::vector&lt;unsigned int&gt; products;
	std::string vname;

	for(; it != student.end(); ++it)
	{
		Name_Product nameprod(it-&gt;vname, it-&gt;nname, it-&gt;GetProduct());

		newStudent.push_back(nameprod);
		products.push_back(it-&gt;GetProduct());
	}

	std::sort(products.begin(), products.end());

	for(std::vector&lt;Name_Product&gt;::iterator itNewStudent(newStudent.begin()); itNewStudent != newStudent.end(); ++itNewStudent)
	{
		if(itNewStudent-&gt;product == products[0])
			vname = itNewStudent-&gt;vname;
	}

	if(!vname.empty())
	{
		for(; it2 != student.end(); ++it2)
		{
			if(it2-&gt;vname == vname)
				return *it2;
		}
	}

	return ::Schueler(&quot;undefined&quot;, &quot;undefined&quot;, 0, 0, 0);
}
</code></pre>
<p>Also falls was ist, ich blicke da selber nicht mehr durch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797768</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Sat, 24 Oct 2009 23:10:03 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sat, 24 Oct 2009 23:28:21 GMT]]></title><description><![CDATA[<p>boar... wenn du schon ne komplett-lösung postest, teste es doch wenigsten einmal...</p>
<pre><code class="language-cpp">struct Name_Product
{
    Name_Product::Name_Product(/*...*/
</code></pre>
<p><code>const unsigned int &amp;newProduct</code></p>
<pre><code class="language-cpp">Schueler::Schueler():
    info(NULL),
    mathe(NULL),
    phy(NULL) { }
</code></pre>
<p>NULL ist für Zeiger...</p>
<pre><code class="language-cpp">Schueler::Schueler(const Schueler &amp;schueler):
    vname(schueler.vname),
    nname(schueler.nname),
    info(schueler.info),
    mathe(schueler.mathe),
    phy(schueler.phy) { }
</code></pre>
<p>rate mal, was der compiler generiert...</p>
<pre><code class="language-cpp">const bool Schueler::operator == (const Schueler &amp;schueler) const
{
    if((info == schueler.info)
     &amp;&amp;(mathe == schueler.mathe)
     &amp;&amp;(phy == schueler.phy))
        return true;

    else
        return false;
}
</code></pre>
<p>1. const bool als rückgabetyp Oo<br />
2. gleiche noten == gleicher schüler?! OO<br />
3. <code>if(true) return true; else return false;</code></p>
<pre><code class="language-cpp">const Schueler Schueler::operator = (const Schueler &amp;schueler) const
{
    return ::Schueler(schueler);
}
</code></pre>
<p>genau das macht op=... nicht!</p>
<pre><code class="language-cpp">const unsigned int Schueler::GetProduct() const
{
    return (info + mathe + phy);
}
</code></pre>
<p>1. const unsigned int? schon wieder so was sinnloses...<br />
2. wieso member fkt?</p>
<pre><code class="language-cpp">void main()
</code></pre>
<p>aha?!</p>
<p><code>char result(NULL);</code><br />
schon wieder fail...</p>
<p>[....]</p>
<p><code>return ::Schueler(&quot;undefined&quot;, &quot;undefined&quot;, 0, 0, 0);</code><br />
aha? na, wo ist hier(kein Namespace weit und breit; und du hast davor nie :: mitgeschrieben und so weiter) der Unterschied zwischen <code>Schueler</code> und <code>::Schueler</code> ?</p>
<p>Man müsste noch viel mehr bemängeln, damit der TO sich nicht irgend ne dumme Idee von dir abguckt und denkt, es wäre so richtig...<br />
Vll hat irgendwer noch Lust, den Rest noch zu bemängeln oder was besseres zu posten^^</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797775</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 24 Oct 2009 23:28:21 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 00:30:06 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>rate mal, was der compiler generiert...</p>
</blockquote>
<p>Also bei mir generiert er alles richtig.</p>
<p>unskilled schrieb:</p>
<blockquote>
<p>1. const bool als rückgabetyp Oo</p>
</blockquote>
<p>Ja? Klär mich bitte auf <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
<p>unskilled schrieb:</p>
<blockquote>
<p>2. gleiche noten == gleicher schüler?! OO</p>
</blockquote>
<p>In diesem Falle ja. Es geht um die Noten.</p>
<p>unskilled schrieb:</p>
<blockquote>
<p>genau das macht op=... nicht!</p>
</blockquote>
<p>Wie auch vorhin: Klär mich auf.</p>
<p>unskilled schrieb:</p>
<blockquote>
<p>1. const unsigned int? schon wieder so was sinnloses...<br />
2. wieso member fkt?</p>
</blockquote>
<p>1. Warum?<br />
2. Warum nicht?</p>
<pre><code class="language-cpp">void main()
</code></pre>
<p>Habe ich von dem TO übernommen und übersehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797793</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Sun, 25 Oct 2009 00:30:06 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 00:55:02 GMT]]></title><description><![CDATA[<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>rate mal, was der compiler generiert...</p>
</blockquote>
<p>Also bei mir generiert er alles richtig.</p>
</blockquote>
<p>Unskilled meinte auch den Default-Kopierkonstruktor. Der macht nämlich genau das, was du da selber getippt hast. Also hast du völlig unnötigen Code geschrieben.</p>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>1. const bool als rückgabetyp Oo</p>
</blockquote>
<p>Ja? Klär mich bitte auf <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
</blockquote>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>1. const unsigned int? schon wieder so was sinnloses...</p>
</blockquote>
<p>1. Warum?</p>
</blockquote>
<p>Diese Rückgabewerte sind sowieso L-Values, wodurch du keine Zuweisung machen kannst. Bei Built-In Typen ist das const unnötig, nur bei eigenen Klassen kann es etwas bringen.</p>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>2. gleiche noten == gleicher schüler?! OO</p>
</blockquote>
<p>In diesem Falle ja. Es geht um die Noten.</p>
</blockquote>
<p>Das ist aber äusserst schlecht für das Verständnis. Wenn man die Operatoren verwendet, dann sollte man ganz logische Beziehungen wählen. Ansonsten nimm lieber eine Funktion: <code>int compareMarks(Student const&amp; lhs, Student const&amp; rhs)</code> .</p>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>genau das macht op=... nicht!</p>
</blockquote>
<p>Wie auch vorhin: Klär mich auf.</p>
</blockquote>
<p>Der Kopierkonstruktor erzeugt ein neues Objekt anhand eines alten. Der operator = erzeugt aber kein neues Objekt. Ich weiss nicht einmal, ob dieser Aufruf standardkonform ist, schliesslich darf man doch nicht einen Konstruktor auf ein bereits konstruiertes Objekt aufrufen, wäre mir zumindest neu. Zudem könntest du es auch einfach dem Kompiler überlassen, der implementiert dir bereits eine solche Funktion.<br />
(Und so am Rande, dadurch ist dein operator = nicht Exceptionsicher)</p>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>2. wieso member fkt?</p>
</blockquote>
<p>2. Warum nicht?</p>
</blockquote>
<p>Lies: <a href="http://magazin.c-plusplus.net/artikel/%DCberladung%20von%20Operatoren%20in%20CPlusPlus%20(Teil%201)" rel="nofollow">Überladung von Operatoren (Teil 1)</a></p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797797</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sun, 25 Oct 2009 00:55:02 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 11:09:55 GMT]]></title><description><![CDATA[<p>Dravere schrieb:</p>
<blockquote>
<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>genau das macht op=... nicht!</p>
</blockquote>
<p>Wie auch vorhin: Klär mich auf.</p>
</blockquote>
<p>Der Kopierkonstruktor erzeugt ein neues Objekt anhand eines alten. Der operator = erzeugt aber kein neues Objekt. Ich weiss nicht einmal, ob dieser Aufruf standardkonform ist, schliesslich darf man doch nicht einen Konstruktor auf ein bereits konstruiertes Objekt aufrufen, wäre mir zumindest neu. Zudem könntest du es auch einfach dem Kompiler überlassen, der implementiert dir bereits eine solche Funktion.<br />
(Und so am Rande, dadurch ist dein operator = nicht Exceptionsicher)</p>
</blockquote>
<p>naja - der aufruf an sich wird schon standard-konform sein - mit dem eigtl objekt passiert ja eigtl gar nichts, es wird einfach nur eine kopie des anderen objekts wiedergegeben...<br />
das &quot;tolle&quot; ist, dass sein op= also gar nichts mit dem objekt an sicht macht...<br />
-&gt; <code>Schueler operator= (const Schueler &amp;other) const</code> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797879</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 25 Oct 2009 11:09:55 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 11:14:24 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/16305">@unskilled</a><br />
Das verstehe ich nicht. Die Klasseninstanzen werden doch mit dem Objekt initialisiert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797881</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797881</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Sun, 25 Oct 2009 11:14:24 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 11:28:24 GMT]]></title><description><![CDATA[<p>Kóyaánasqatsi schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/16305">@unskilled</a><br />
Das verstehe ich nicht. Die Klasseninstanzen werden doch mit dem Objekt initialisiert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>in wie fern? wovon redest du?<br />
vom op=?<br />
der sieht ja in nem einfachen bsp so aus:</p>
<pre><code class="language-cpp">struct foo
{
  int a;

  foo() : a(0) {}
  foo(int _a) : a(_a) {}

  foo(const foo &amp;other) : a(other.a) {}
  foo&amp; operator= (const foo &amp;other) {a = other.a; return *this;}
};
</code></pre>
<p>man sieht schon, dass der copy ctor und assignment op sich extrem ähnlich sind...<br />
aber das gleiche tun sie eben nicht.<br />
Wenn du jetzt noch mal an deinen op= denkst:</p>
<pre><code class="language-cpp">foo operator= (const foo &amp;other)
{
  foo tmp(other);
  return tmp;
}
</code></pre>
<p>macht so ziemlich gar nichts von dem, was ein op= machen sollte - nämlich das objekt verändern (und einen verweis(keine kopie) des veränderten objekts wiedergeben)<br />
dravere hatte dir den link(artikel zur op-überladung) schon gegeben, der dir vrmtl die erleuchtung bringt <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>
<p>und so macht man es dann, wenn man es toll machen möchte ;o)</p>
<pre><code class="language-cpp">struct foo
{
  int a;

  explicit foo(int _a = int()) : a(_a) {}

  foo(const foo &amp;other) : a(other.a) {}
  void swap(foo &amp;other) {using std::swap; swap(a, other.a);}
  foo&amp; operator= (const foo &amp;other) {foo to_swap(other); swap(other); return *this}
};
</code></pre>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797884</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 25 Oct 2009 11:28:24 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 11:35:48 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<pre><code class="language-cpp">foo&amp; operator= (const foo &amp;other) {foo to_swap(other); swap(other); return *this;}
</code></pre>
</blockquote>
<p>Besser</p>
<pre><code class="language-cpp">foo&amp; operator= (foo other) {swap(other); return *this;}
</code></pre>
<p>nehmen und auf copy elision hoffen. <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/1797891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797891</guid><dc:creator><![CDATA[Ryuzaki]]></dc:creator><pubDate>Sun, 25 Oct 2009 11:35:48 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 11:43:49 GMT]]></title><description><![CDATA[<p>Ryuzaki schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<pre><code class="language-cpp">foo&amp; operator= (const foo &amp;other) {foo to_swap(other); swap(other); return *this;}
</code></pre>
</blockquote>
<p>Besser</p>
<pre><code class="language-cpp">foo&amp; operator= (foo other) {swap(other); return *this;}
</code></pre>
<p>nehmen und auf copy elision hoffen. <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>
</blockquote>
<p>ja - das thema hatten wir glaub ich ab und an schon mal - und es kam jedes ma das selbe raus: unnötiges impl.-detail und das hat nix im header zu suchen - aber bedingt durch die andere signatur ist es eben doch schon dort zu finden...<br />
ich werds weiter mit const reference machen und nur, wenn ich iwann merk, dass ich wegen des op= performace-probleme hab, werd ich es ändern...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797893</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797893</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 25 Oct 2009 11:43:49 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 12:11:45 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>unnötiges impl.-detail und das hat nix im header zu suchen - aber bedingt durch die andere signatur ist es eben doch schon dort zu finden...<br />
ich werds weiter mit const reference machen und nur, wenn ich iwann merk, dass ich wegen des op= performace-probleme hab, werd ich es ändern...</p>
</blockquote>
<p>Das verstehe ich jetzt überhaupt nicht. WARUM bleibst Du bei const&amp; ? Kannst Du mir ein Beispiel programmieren, wo const&amp; einen Vorteil hat?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797912</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 25 Oct 2009 12:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to maximum im Array finden on Sun, 25 Oct 2009 12:37:42 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>unskilled schrieb:</p>
<blockquote>
<p>unnötiges impl.-detail und das hat nix im header zu suchen - aber bedingt durch die andere signatur ist es eben doch schon dort zu finden...<br />
ich werds weiter mit const reference machen und nur, wenn ich iwann merk, dass ich wegen des op= performace-probleme hab, werd ich es ändern...</p>
</blockquote>
<p>Das verstehe ich jetzt überhaupt nicht. WARUM bleibst Du bei const&amp; ? Kannst Du mir ein Beispiel programmieren, wo const&amp; einen Vorteil hat?</p>
</blockquote>
<p>immer dann, wenn ich die exceptionsicherheit noch anders erhalten kann, außer durch copy&amp;swap bzw sich copy&amp;swap einfach nicht lohnt...</p>
<pre><code class="language-cpp">struct X
{
private:
  int id;
  int count;
  std::string beschreibung;
public:
  X(int id, int count): id(id), count(count), beschreibung(db_lookup(id)) {}
  X(const X&amp; x) : id(x.id), count(x.count), beschreibung(x.beschreibung) {}

  X&amp; operator= (const X &amp;x)
  {
    beschreibung = x.beschreibung;
    id = x.id;
    count = x.id;
    return *this;
  }
};
</code></pre>
<p>ist noch immer exceptionsafe und hat nur 2 int-zuweisungen - im ggnsatz zu 2 mal nem dreieckstausch (warum hat tausch eigtl keinen plural? &gt;.&lt;)</p>
<p>wenn ich also erst op= durch das copy&amp;swap idiom erledigt hab und mir dann auffällt, dass dort mein flaschenhals ist, müsste ich nur mein *.cpp file ändern - ihr müsstet zusätzlich noch den header ändern...<br />
da kann man sicherlich auch bsp konstruieren, wo es sich richtig lohnt...</p>
<p>steht eigtl iwo, dass der compiler die copy elision so nicht mehr durchführen darf oder sind die compiler (bisher) nur zu dumm dazu?</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1797925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1797925</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 25 Oct 2009 12:37:42 GMT</pubDate></item></channel></rss>