<?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[[Erledigt] Variable Argumente auswerten]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich möchte einen std::vector in Abhängigkeit von der Argumentzahl füttern:</p>
<p>Hier die Klasse:</p>
<pre><code class="language-cpp">class Knot : public Topoobject{

private:

	std::vector&lt;Coord&gt; coordinatesystem;

public:

	Knot();
	Knot(Coord first);
	Knot(Coord first,Coord second);
	Knot(Coord first,Coord second,Coord third);

	Coord get_sys(puint format) const;
	void set_sys(Coord new_coord,puint format);

};
</code></pre>
<p>So habe ich es bisher gemacht:</p>
<pre><code class="language-cpp">Knot::Knot():Topoobject(propknot) { 

	for(int i=0;i&lt;Geotopology::maxdim;i++){
		Coord tmpcoord;
		this-&gt;coordinatesystem[i] = tmpcoord;
	}

}

Knot::Knot(Coord new_first):Topoobject(propknot){ 
	this-&gt;coordinatesystem[0] = new_first;
}

Knot::Knot(Coord new_first,Coord new_second):Topoobject(propknot){ 
	this-&gt;coordinatesystem[0] = new_first;
	this-&gt;coordinatesystem[1] = new_second;
}

Knot::Knot(Coord new_first,Coord new_second,Coord new_third):Topoobject(propknot){ 
	this-&gt;coordinatesystem[0] = new_first;
	this-&gt;coordinatesystem[1] = new_second;
	this-&gt;coordinatesystem[2] = new_third;
}

Coord Knot::get_sys(puint sys_id) const { 
	assert(sys_id&lt;coordinatesystem.size() &amp;&amp; sys_id &gt; 0);
	return this-&gt;coordinatesystem[sys_id]; 
}

void Knot::set_sys(Coord coordinate,puint sys_id) { 
	assert(sys_id&lt;coordinatesystem.size() &amp;&amp; sys_id &gt; 0);
	this-&gt;coordinatesystem[sys_id] = coordinate;
}
</code></pre>
<p>Fängt aber nach der dritten Dimension an zu stinken,<br />
wegen den zusätzlichen Konstruktoren.</p>
<p>Wie könnte man diese variable Anzahl in den Vektor bringen?<br />
Wie ist es bei der Übergabe? Kann ich hier irgendwo, vor allem in<br />
get_ oder set_ mit Referenzen arbeiten?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/269298/erledigt-variable-argumente-auswerten</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 02:26:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/269298.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Jun 2010 18:57:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 19:48:05 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich möchte einen std::vector in Abhängigkeit von der Argumentzahl füttern:</p>
<p>Hier die Klasse:</p>
<pre><code class="language-cpp">class Knot : public Topoobject{

private:

	std::vector&lt;Coord&gt; coordinatesystem;

public:

	Knot();
	Knot(Coord first);
	Knot(Coord first,Coord second);
	Knot(Coord first,Coord second,Coord third);

	Coord get_sys(puint format) const;
	void set_sys(Coord new_coord,puint format);

};
</code></pre>
<p>So habe ich es bisher gemacht:</p>
<pre><code class="language-cpp">Knot::Knot():Topoobject(propknot) { 

	for(int i=0;i&lt;Geotopology::maxdim;i++){
		Coord tmpcoord;
		this-&gt;coordinatesystem[i] = tmpcoord;
	}

}

Knot::Knot(Coord new_first):Topoobject(propknot){ 
	this-&gt;coordinatesystem[0] = new_first;
}

Knot::Knot(Coord new_first,Coord new_second):Topoobject(propknot){ 
	this-&gt;coordinatesystem[0] = new_first;
	this-&gt;coordinatesystem[1] = new_second;
}

Knot::Knot(Coord new_first,Coord new_second,Coord new_third):Topoobject(propknot){ 
	this-&gt;coordinatesystem[0] = new_first;
	this-&gt;coordinatesystem[1] = new_second;
	this-&gt;coordinatesystem[2] = new_third;
}

Coord Knot::get_sys(puint sys_id) const { 
	assert(sys_id&lt;coordinatesystem.size() &amp;&amp; sys_id &gt; 0);
	return this-&gt;coordinatesystem[sys_id]; 
}

void Knot::set_sys(Coord coordinate,puint sys_id) { 
	assert(sys_id&lt;coordinatesystem.size() &amp;&amp; sys_id &gt; 0);
	this-&gt;coordinatesystem[sys_id] = coordinate;
}
</code></pre>
<p>Fängt aber nach der dritten Dimension an zu stinken,<br />
wegen den zusätzlichen Konstruktoren.</p>
<p>Wie könnte man diese variable Anzahl in den Vektor bringen?<br />
Wie ist es bei der Übergabe? Kann ich hier irgendwo, vor allem in<br />
get_ oder set_ mit Referenzen arbeiten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1915969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1915969</guid><dc:creator><![CDATA[darkfate]]></dc:creator><pubDate>Tue, 22 Jun 2010 19:48:05 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 19:06:03 GMT]]></title><description><![CDATA[<p>Warum benutzt du einen vector, wenn die Anzahl fest steht? (ich nehme mal an, dass du 3 Dimensional bleiben willst).</p>
<p>Für 1,2 oder 3 Dimensionale Knoten würde ich sogar verschiedene Klassen machen. In C++0x gibt es dann variadic templates, mit denen man das auch ein wenig generischer machen kann und nur noch ein template braucht.</p>
<p>Ansonsten allgemein könntest du einen Container ja an den Konstruktor übergeben und dann mit einer Schleife füllen, respektive einfach kopieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1915975</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1915975</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 22 Jun 2010 19:06:03 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 19:13:22 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>ich nehme mal an, dass du 3 Dimensional bleiben willst</p>
</blockquote>
<p>Ich habe bisher nur bis drei geschafft, dann wars mir zu doof.<br />
Es geht tatsächlich weiter als drei.<br />
Alleine wegen der Wiederverwertbarkeit der variablen Argumente,<br />
würde ich es gern sehen. In C gibt es ja die weniger schöne ( ... )</p>
<p>drakon schrieb:</p>
<blockquote>
<p>Für 1,2 oder 3 Dimensionale Knoten würde ich sogar verschiedene Klassen machen.</p>
</blockquote>
<p>Warum?</p>
<p>drakon schrieb:</p>
<blockquote>
<p>In C++0x gibt es dann variadic templates, mit denen man das auch ein wenig generischer machen kann und nur noch ein template braucht.</p>
</blockquote>
<p>Templates, vorallem deren Kompilerfehlermeldungen, rufen bei mir regelmäßig frustrationen hervor.</p>
<p>drakon schrieb:</p>
<blockquote>
<p>Ansonsten allgemein könntest du einen Container ja an den Konstruktor übergeben und dann mit einer Schleife füllen, respektive einfach kopieren.</p>
</blockquote>
<p>Hatte ich mir auch schon überlegt, da der Kontainer aber sowieso irgendwann gefüllt werden muss...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1915979</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1915979</guid><dc:creator><![CDATA[darkfate]]></dc:creator><pubDate>Tue, 22 Jun 2010 19:13:22 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 19:22:08 GMT]]></title><description><![CDATA[<p>Ok, wenn es mehr als 3 werden, dann würde ich da wirklich einfach einen Container nehmen und den in der Klasse mit dem initialisieren. Fertig.</p>
<p>Das was du in C mit der Ellipse (...) meinst kommt eben in C++0x mit variadic templates wieder, aber diesemal typsicher. <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="😉"
    /><br />
Aber das wäre dann weniger deine Wahl, da du das ja volkommen dynamischen haben möchtest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1915984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1915984</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 22 Jun 2010 19:22:08 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 19:47:46 GMT]]></title><description><![CDATA[<p>Na gut, da es scheinbar nicht anders klappt bleibt es bei dem hier, falls jemand die Sucheb benutzt <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>
<pre><code class="language-cpp">Knot::Knot(puint maxdim ...){

	assert(maxdim&lt;=Geotopology::maxdim);

	va_list vl;
	va_start(vl,maxdim);
	this-&gt;coordinatesystem[0] = va_arg(vl,Coord);
	for (int i=1;i&lt;maxdim;i++) this-&gt;coordinatesystem[i] = va_arg(vl,Coord);
	va_end(vl);

}
</code></pre>
<p>Zwar ein wenig unschön, sollte aber funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1915990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1915990</guid><dc:creator><![CDATA[darkfate]]></dc:creator><pubDate>Tue, 22 Jun 2010 19:47:46 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 20:25:54 GMT]]></title><description><![CDATA[<p>Warum denn jetzt kein Container?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1916008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1916008</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Tue, 22 Jun 2010 20:25:54 GMT</pubDate></item><item><title><![CDATA[Reply to [Erledigt] Variable Argumente auswerten on Tue, 22 Jun 2010 20:29:34 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<p>Warum denn jetzt kein Container?</p>
</blockquote>
<p>Weil er an verschiedenen Stellen erstmal gebaut werden müsste.<br />
So habe ich mögliche Fehler an einer Quelle.</p>
<p>Danke für die Hilfe übrigens.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1916010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1916010</guid><dc:creator><![CDATA[darkfate]]></dc:creator><pubDate>Tue, 22 Jun 2010 20:29:34 GMT</pubDate></item></channel></rss>