<?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[vektoren mit strukturen kopieren]]></title><description><![CDATA[<p>Also ich gebe einen Vektor per main funktion an den konstruktor einer klasse und möchte dort erreichen, das der vektor in der klasse , gleich dem übergebenen vektor ist.</p>
<p>Nur wie stell ich das an?</p>
<p>Habs so probiert:<br />
struktur:</p>
<pre><code>struct xy_point
{
	double x;  
	double y;  
};
</code></pre>
<p>main fkt</p>
<pre><code>int main()
{
	std::vector &lt;xy_point&gt; a_xy(5);  //Array mit 5 Punkten (10 Punkte max!)
    //vordefiniertes Polygon
    a_xy[0].x=1.0; 
	a_xy[0].y=4.0;
	a_xy[1].x=2.0; 
	a_xy[1].y=1.0;
	a_xy[2].x=4.5; 
	a_xy[2].y=1.0;
	a_xy[3].x=6.0; 
	a_xy[3].y=3.0;
	a_xy[4].x=3.5; 
	a_xy[4].y=5.0;

	cout&lt;&lt;a_xy.size() &lt;&lt;endl;  //Anzahl der koordinaten
        POLYGON instanz(50,100,a_xy);
	return 0;
}
</code></pre>
<p>konstruktor</p>
<pre><code>POLYGON(double a_x_pos,double a_y_pos,std::vector&lt;xy_point&gt; a_xy)
{
 xy=a_xy;   //Hier liegt der Fehler!!!
            //Wie sieht die Zuweisung richtig aus?
}
</code></pre>
<p>klasse:</p>
<pre><code>class POLYGON  
{
public:
	POLYGON(double a_x_pos,double a_y_pos,std::vector&lt;xy_point&gt; a_xy); //Prototyp Konstruktor
	POLYGON();
	virtual ~POLYGON();

private:
	std::vector&lt;xy_point&gt; xy;
	double x_pos;
	double y_pos;
	double flaecheninhalt;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/195950/vektoren-mit-strukturen-kopieren</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 05:38:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/195950.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Oct 2007 19:42:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to vektoren mit strukturen kopieren on Tue, 23 Oct 2007 19:45:55 GMT]]></title><description><![CDATA[<p>Also ich gebe einen Vektor per main funktion an den konstruktor einer klasse und möchte dort erreichen, das der vektor in der klasse , gleich dem übergebenen vektor ist.</p>
<p>Nur wie stell ich das an?</p>
<p>Habs so probiert:<br />
struktur:</p>
<pre><code>struct xy_point
{
	double x;  
	double y;  
};
</code></pre>
<p>main fkt</p>
<pre><code>int main()
{
	std::vector &lt;xy_point&gt; a_xy(5);  //Array mit 5 Punkten (10 Punkte max!)
    //vordefiniertes Polygon
    a_xy[0].x=1.0; 
	a_xy[0].y=4.0;
	a_xy[1].x=2.0; 
	a_xy[1].y=1.0;
	a_xy[2].x=4.5; 
	a_xy[2].y=1.0;
	a_xy[3].x=6.0; 
	a_xy[3].y=3.0;
	a_xy[4].x=3.5; 
	a_xy[4].y=5.0;

	cout&lt;&lt;a_xy.size() &lt;&lt;endl;  //Anzahl der koordinaten
        POLYGON instanz(50,100,a_xy);
	return 0;
}
</code></pre>
<p>konstruktor</p>
<pre><code>POLYGON(double a_x_pos,double a_y_pos,std::vector&lt;xy_point&gt; a_xy)
{
 xy=a_xy;   //Hier liegt der Fehler!!!
            //Wie sieht die Zuweisung richtig aus?
}
</code></pre>
<p>klasse:</p>
<pre><code>class POLYGON  
{
public:
	POLYGON(double a_x_pos,double a_y_pos,std::vector&lt;xy_point&gt; a_xy); //Prototyp Konstruktor
	POLYGON();
	virtual ~POLYGON();

private:
	std::vector&lt;xy_point&gt; xy;
	double x_pos;
	double y_pos;
	double flaecheninhalt;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1390828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390828</guid><dc:creator><![CDATA[Dragonslayer]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:45:55 GMT</pubDate></item><item><title><![CDATA[Reply to vektoren mit strukturen kopieren on Tue, 23 Oct 2007 19:52:47 GMT]]></title><description><![CDATA[<p>Es wäre sehr hilfreich wenn du uns die genaue Fehlermeldung postest die du bekommst!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390835</guid><dc:creator><![CDATA[TheRightWay]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:52:47 GMT</pubDate></item><item><title><![CDATA[Reply to vektoren mit strukturen kopieren on Tue, 23 Oct 2007 19:59:31 GMT]]></title><description><![CDATA[<p>--------------------Konfiguration: 3Sem_Testat1 - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
POLYGON.cpp<br />
C:\Programme\Microsoft Visual Studio\MyProjects\3Sem_Testat3\POLYGON.cpp(37) : warning C4508: 'POLYGON' : Funktion sollte einen Wert zurueckgeben; Ergebnistyp 'void' angenommen<br />
Linker-Vorgang läuft...<br />
main.obj : error LNK2001: Nichtaufgeloestes externes Symbol &quot;public: __thiscall POLYGON::POLYGON(double,double,class std::vector&lt;struct xy_point,class std::allocator&lt;struct xy_point&gt; &gt;)&quot; (??0POLYGON@@QAE@NNV?<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>v</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>o</mi><mi>r</mi><mi mathvariant="normal">@</mi><mi>U</mi><mi>x</mi><mi>y</mi><mi mathvariant="normal">_</mi><mi>p</mi><mi>o</mi><mi>i</mi><mi>n</mi><mi>t</mi><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">vector@Uxy\_point@@V?</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:1.00444em;vertical-align:-0.31em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.03588em;">v</span><span class="mord mathit">e</span><span class="mord mathit">c</span><span class="mord mathit">t</span><span class="mord mathit">o</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.10903em;">U</span><span class="mord mathit">x</span><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mord mathrm" style="margin-right:0.02778em;">_</span><span class="mord mathit">p</span><span class="mord mathit">o</span><span class="mord mathit">i</span><span class="mord mathit">n</span><span class="mord mathit">t</span><span class="mord mathrm">@</span><span class="mord mathrm">@</span><span class="mord mathit" style="margin-right:0.22222em;">V</span><span class="mclose">?</span></span></span></span>allocator@Uxy_point<br />
@@@std@@@std@@@Z)<br />
Debug/3Sem_Testat3.exe : fatal error LNK1120: 1 unaufgeloeste externe Verweise<br />
Fehler beim Ausführen von link.exe.</p>
<p>3Sem_Testat3.exe - 2 Fehler, 1 Warnung(en)</p>
<p>edit:<br />
hab den fehler gefunden!<br />
der konstruktor war kein konstruktor und konnte xy nicht kennen weil</p>
<pre><code>POLYGON::
//vor
POLYGON(double a_x_pos,double a_y_pos,std::vector&lt;xy_point&gt; a_xy)
</code></pre>
<p>fehlte.<br />
hm wohl beim kopieren verschütt gegangen ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390836</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390836</guid><dc:creator><![CDATA[Dragonslayer]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:59:31 GMT</pubDate></item><item><title><![CDATA[Reply to vektoren mit strukturen kopieren on Tue, 23 Oct 2007 19:59:21 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">:arrow_right: POLYGON::POLYGON(double a_x_pos,double a_y_pos,std::vector&lt;xy_point&gt; a_xy) 
{ 
 xy=a_xy;   //Hier liegt der Fehler!!! 
            //Wie sieht die Zuweisung richtig aus? 
}
</code></pre>
<p>Sonst weiss der Compiler nicht dass die Methode zur Klasse POLYGON gehört.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390838</guid><dc:creator><![CDATA[TheRightWay]]></dc:creator><pubDate>Tue, 23 Oct 2007 19:59:21 GMT</pubDate></item><item><title><![CDATA[Reply to vektoren mit strukturen kopieren on Tue, 23 Oct 2007 20:24:22 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;typename datatype=double&gt;
struct point
{
    datatype x;  
    datatype y;
    point(datatype const&amp; x, datatype const&amp; y) : x(x), y(y) {}
    point(point const&amp; rhs) : x(rhs.x), y(rhs.y) {}
};

class polygon : public shape  
{
public:
    polygon(point const&amp; pos, std::vector&lt;point&gt; const&amp; xy) : m_pos(pos), m_xy(xy) {}
    polygon() : m_x(0.0), m_y(0.0) {};
    virtual ~polygon() {};

private:
    std::vector&lt;point&gt; m_xy;
    point m_pos;
};
</code></pre>
<p>... damit da nicht unnötig Performance verschwendet wird, weil dein Vektor 2x kopiert wird ^^ So wird er nur einmal kopiert <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="🙂"
    /><br />
Dann kannst du deine beiden Werte für die pos auch in einen Punkt packen ... durch den überladenen Konstruktor geht jetzt:</p>
<pre><code class="language-cpp">int main()
{
    std::vector&lt;point&gt; data;
    data.push_back(point(1.0, 4.0));
    data.push_back(point(2.0, 1.0));
    data.push_back(point(4.5, 1.0));
    data.push_back(point(6.0, 3.0));
    data.push_back(point(3.5, 5.0));
    polygon shape_inst(point(50.0, 100.0), data);   
}
</code></pre>
<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1390863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1390863</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 23 Oct 2007 20:24:22 GMT</pubDate></item></channel></rss>