<?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[Resize eines static vector aus einem externen struct]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgendes Problem:</p>
<p>Ich habe einen externen Struct, welcher ein static vector enthält.<br />
Nun möchte ich diesen Vektor mit Hilfe von resize modifizieren.<br />
Leider bekomme ich folgende Fehlermeldung:</p>
<p>error LNK2019: unresolved external symbol &quot;public: static class std::vector&lt;struct float2,class std::allocator&lt;struct float2&gt; &gt; teststruct::test&quot; (?test@teststruct@@2V?<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>f</mi><mi>l</mi><mi>o</mi><mi>a</mi><mi>t</mi><mn>2</mn><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">vector@Ufloat2@@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:0.8888799999999999em;vertical-align:-0.19444em;"></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" style="margin-right:0.10764em;">f</span><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">o</span><span class="mord mathit">a</span><span class="mord mathit">t</span><span class="mord mathrm">2</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@Ufloat2@@@std@@@std@@A) referenced in function &quot;void __cdecl task2Trajectoryplanner::write2InputStructure(class CFreespaceDataChannelMsg const &amp;)&quot; (?write2InputStructure@task2Trajectoryplanner@@YAXABVCFreespaceDataChannelMsg@@@Z)</p>
<p>Hier ist der Code dazu:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
using namespace std;

//*********************

struct float2 {
	float2(float x, float y) {
		float2::x = x;
		float2::y = y;
	}

	float2() {
		x = 0;
		y = 0;
	}

	float x;
	float y;
};

//*********************

struct teststruct
		{
			 static std::vector&lt;float2&gt; test;
		};

extern struct teststruct teststruct1;

//*********************

void write2InputStructure(const CFreespaceDataChannelMsg &amp; fs )
{

		teststruct1.test.resize(5);
}
</code></pre>
<p>Wäre super, wenn ihr mir weiterhelfen könntet.</p>
<p>viele Grüße,<br />
Eric</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/308096/resize-eines-static-vector-aus-einem-externen-struct</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 21:11:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/308096.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Sep 2012 14:07:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Fri, 14 Sep 2012 14:07:20 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgendes Problem:</p>
<p>Ich habe einen externen Struct, welcher ein static vector enthält.<br />
Nun möchte ich diesen Vektor mit Hilfe von resize modifizieren.<br />
Leider bekomme ich folgende Fehlermeldung:</p>
<p>error LNK2019: unresolved external symbol &quot;public: static class std::vector&lt;struct float2,class std::allocator&lt;struct float2&gt; &gt; teststruct::test&quot; (?test@teststruct@@2V?<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>f</mi><mi>l</mi><mi>o</mi><mi>a</mi><mi>t</mi><mn>2</mn><mi mathvariant="normal">@</mi><mi mathvariant="normal">@</mi><mi>V</mi><mo>?</mo></mrow><annotation encoding="application/x-tex">vector@Ufloat2@@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:0.8888799999999999em;vertical-align:-0.19444em;"></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" style="margin-right:0.10764em;">f</span><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">o</span><span class="mord mathit">a</span><span class="mord mathit">t</span><span class="mord mathrm">2</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@Ufloat2@@@std@@@std@@A) referenced in function &quot;void __cdecl task2Trajectoryplanner::write2InputStructure(class CFreespaceDataChannelMsg const &amp;)&quot; (?write2InputStructure@task2Trajectoryplanner@@YAXABVCFreespaceDataChannelMsg@@@Z)</p>
<p>Hier ist der Code dazu:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
using namespace std;

//*********************

struct float2 {
	float2(float x, float y) {
		float2::x = x;
		float2::y = y;
	}

	float2() {
		x = 0;
		y = 0;
	}

	float x;
	float y;
};

//*********************

struct teststruct
		{
			 static std::vector&lt;float2&gt; test;
		};

extern struct teststruct teststruct1;

//*********************

void write2InputStructure(const CFreespaceDataChannelMsg &amp; fs )
{

		teststruct1.test.resize(5);
}
</code></pre>
<p>Wäre super, wenn ihr mir weiterhelfen könntet.</p>
<p>viele Grüße,<br />
Eric</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2251253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251253</guid><dc:creator><![CDATA[eric84]]></dc:creator><pubDate>Fri, 14 Sep 2012 14:07:20 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Fri, 14 Sep 2012 14:14:33 GMT]]></title><description><![CDATA[<p>Hast du</p>
<pre><code class="language-cpp">teststruct1
</code></pre>
<p>auch definiert?</p>
<pre><code class="language-cpp">extern struct teststruct teststruct1;
</code></pre>
<p>ist nur eine Deklaration. Ist dir klar, was</p>
<pre><code class="language-cpp">extern
</code></pre>
<p>bedeutet?</p>
<p>Außerdem muss es</p>
<pre><code class="language-cpp">void write2InputStructure(const CFreespaceDataChannelMsg &amp; fs )
{
    teststruct::test.resize(5);
}
</code></pre>
<p>heißen, da test static ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2251255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251255</guid><dc:creator><![CDATA[Hyde++ 0]]></dc:creator><pubDate>Fri, 14 Sep 2012 14:14:33 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Fri, 14 Sep 2012 14:58:33 GMT]]></title><description><![CDATA[<p>Erstmal vielen Dank für deine Antwort.<br />
Den Unterschied zwischen einer Deklaration und Definition habe ich mir grad nochmal klar gemacht und somit brauche ich natürlich noch die Definition. Habe sie eingefügt, ich hoffe an der richtigen Stelle, und den Code angepasst:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
using namespace std;

//*********************

struct float2 {
	float2(float x, float y) {
		float2::x = x;
		float2::y = y;
	}

	float2() {
		x = 0;
		y = 0;
	}

	float x;
	float y;
};

//*********************

struct teststruct
		{
			 static std::vector&lt;float2&gt; test;
		};

extern struct teststruct teststruct1;

//*********************

void write2InputStructure(const CFreespaceDataChannelMsg &amp; fs )
{
	struct teststruct teststruct1;
		teststruct1::test.resize(5);
}
</code></pre>
<p>Leider bekomme ich nun folgende Fehlermeldungen:</p>
<p>1&gt;..\..\sandbox\src\Trajectoryplanner\src\Framework\RunTask\Task2Appl_Trajectoryplanner.cpp(100) : error C2510: 'teststruct1' : left of '::' must be a class/struct/union<br />
1&gt;..\..\sandbox\src\Trajectoryplanner\src\Framework\RunTask\Task2Appl_Trajectoryplanner.cpp(100) : error C2065: 'test' : undeclared identifier<br />
1&gt;..\..\sandbox\src\Trajectoryplanner\src\Framework\RunTask\Task2Appl_Trajectoryplanner.cpp(100) : error C2228: left of '.resize' must have class/struct/union</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2251260</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251260</guid><dc:creator><![CDATA[eric84]]></dc:creator><pubDate>Fri, 14 Sep 2012 14:58:33 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Fri, 14 Sep 2012 15:07:01 GMT]]></title><description><![CDATA[<p>eric84 schrieb:</p>
<blockquote>
<p>Habe sie eingefügt, ich hoffe an der richtigen Stelle...</p>
</blockquote>
<p>Scheint mir nicht so.<br />
1. Wenn hättest du sie außerhalb der Funktion definieren müssen. Wobei mir ohnehin der Sinn einer Instanz an dieser Stelle fehlt: Enthält doch nur statische Member.<br />
2. extern macht meines Erachtens allgemein in einer cpp-Datei keinen Sinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2251264</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251264</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Fri, 14 Sep 2012 15:07:01 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Fri, 14 Sep 2012 15:25:14 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;vector&gt;

struct float2 {
    float2(float x, float y) {
        float2::x = x;
        float2::y = y;
    }

    float2() {
        x = 0;
        y = 0;
    }

    float x;
    float y;
};

struct teststruct
{
     static std::vector&lt;float2&gt; test;  
};

std::vector&lt;float2&gt; teststruct::test;  // definition hat gefehlt

int main()
{
    //teststruct t1;
    //t1.test.resize(5);
    // oder
    teststruct::test.resize(15);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2251267</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2251267</guid><dc:creator><![CDATA[__]]></dc:creator><pubDate>Fri, 14 Sep 2012 15:25:14 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Mon, 24 Sep 2012 10:14:39 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>erstmal vielen Dank für eure Antworten!<br />
Im nächsten Schritte möchte ich gerne ein struct in einem struct verwenden, weiß aber nicht, wie ich das Beispiel aus dem letzten verändern muss.<br />
Nochmal kurz zum Kontext:<br />
Das Beispiel muss nicht unbedingt Sinn machen, denn ich hab es so reduziert, dass das eigentliche Problem dargestellt. Eigentlich ist es Teil eines großen vorgegebenen Frameworks. Das heißt, dass die Art und Weise der Deklaration des Structs vorgegeben ist, auch z.B. die Verwendung von extern.<br />
So jetzt zum Biespiel:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;

struct float2 {
    float2(float x, float y) {
        float2::x = x;
        float2::y = y;
    }

    float2() {
        x = 0;
        y = 0;
    }

    float x;
    float y;
};

extern struct teststruct t1;

struct inneresstruct
{
     static std::vector&lt;float2&gt; test;  
};

struct teststruct
{
inneresstruct istr;
};

std::vector&lt;float2&gt; inneresstruct::test;  

int main()
{
    teststruct t1;
    t1.istr.test.resize(5);

}
</code></pre>
<p>Ich glaube, ich habe da noch ein bißchen Chaos drin <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 />
Denn habe die Fehlermeldung:<br />
1&gt;..\..\sandbox\src\Trajectoryplanner\src\Framework\RunTask\Task2Appl_Trajectoryplanner.cpp(109) : warning C4101: 't1' : unreferenced local variable</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2253912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2253912</guid><dc:creator><![CDATA[eric84]]></dc:creator><pubDate>Mon, 24 Sep 2012 10:14:39 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Mon, 24 Sep 2012 13:08:53 GMT]]></title><description><![CDATA[<p>eric84 schrieb:</p>
<blockquote>
<p>Das Beispiel muss nicht unbedingt Sinn machen, denn ich hab es so reduziert, dass das eigentliche Problem dargestellt. Eigentlich ist es Teil eines großen vorgegebenen Frameworks. Das heißt, dass die Art und Weise der Deklaration des Structs vorgegeben ist, auch z.B. die Verwendung von extern.</p>
</blockquote>
<p>Dann nehme ich mal an das &quot;extern&quot; in einem Header steht? Wenn nicht ist es weiterhin nonsense. Zudem VERSTEHST du extern nicht.</p>
<p>Weißt du überhaupt was extern macht?</p>
<pre><code class="language-cpp">// Header
extern teststruct t1; // &lt;-- Alleine für sich nicht ausreichend
</code></pre>
<p>In einer cpp muss die eigentliche Deklaration stehen, wenn es wirklich Teil eines Frameworks ist, sollte sie auch existieren. Zudem wird hier eine globale Variable als Gegenstück erwartet.</p>
<pre><code class="language-cpp">// Source
teststruct t1; // &lt;-- Gegenstück (globale Variable)
</code></pre>
<p>Daher ist auch dein restlicher Code Unsinn. Deine lokale Variable hat nichts mit der &quot;extern&quot;-Deklaration zu tun.</p>
<p>Edit: Unnötige &quot;stuct&quot;-Angaben entfernt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2253913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2253913</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 24 Sep 2012 13:08:53 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Mon, 24 Sep 2012 13:01:06 GMT]]></title><description><![CDATA[<p>Ich habe das bislang mit dem extern so verstanden, dass ich die Variable bzw. das Struct damit erstmal nur deklariere und somit sage, dass es existiert und ich es dann in der cpp initialisiere.</p>
<p>Du hast recht, ich hätte erkenntlich machen sollen, dass ein Teil des Codes im header steht:</p>
<pre><code class="language-cpp">//headerfile1.h
#include &lt;vector&gt;

struct float2 {
    float2(float x, float y) {
        float2::x = x;
        float2::y = y;
    }

    float2() {
        x = 0;
        y = 0;
    }

    float x;
    float y;
};

//headerfile2
extern struct teststruct t1;

struct inneresstruct
{
     static std::vector&lt;float2&gt; test;  
};

struct teststruct
{
inneresstruct istr;
};

// Source file
#include &quot;headerfile1.h&quot;
#include &quot;headerfile2.h&quot; 

std::vector&lt;float2&gt; inneresstruct::test;  //brauch ich das?

void write2InputStructure(const CFreespaceDataChannelMsg		 &amp; fs )
{
    struct teststruct t1;
    t1.istr.test.resize(5);

}
</code></pre>
<p>Leider tue ich mich trotzdem noch immer schwer, wie ich jetzt weitermachen kann, denn ich bin noch nicht wirklich fit in C++ und muss leider damit auskommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2253953</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2253953</guid><dc:creator><![CDATA[eric84]]></dc:creator><pubDate>Mon, 24 Sep 2012 13:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Mon, 24 Sep 2012 13:12:00 GMT]]></title><description><![CDATA[<p>Warum willst Du eine Instanz einer Struktur erzeugen, die keine Member enthält? Weißt Du, was static in dem Zusammenhang bedeutet?</p>
<p>Vielleicht schilderst Du mal, was Du überhaupt erreichen willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2253955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2253955</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 24 Sep 2012 13:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Mon, 24 Sep 2012 13:13:17 GMT]]></title><description><![CDATA[<p>eric84 schrieb:</p>
<blockquote>
<p>Ich habe das bislang mit dem extern so verstanden, dass ich die Variable bzw. das Struct damit erstmal nur deklariere und somit sage, dass es existiert und ich es dann in der cpp initialisiere.</p>
</blockquote>
<p>Und nochmals: Wo definierst die die Variable? Das extern sagt aus das du es in der Source definierst - die Definition fehlt noch immer. Du hast extern eine <strong>globale</strong> Variable (übrigens ist hier das stuct-Schlüsselwort unnötig, das ist C-Stil) deklariert, in deiner Sourcedatei existiert aber keine solche (außer eine Lokale [auch hier ist struct unnötig], die nichts mit der extern deklarierten zu tun hat).</p>
<p>Alles das wurde aber schon mehrmals gesagt - nur liest du es scheinbar nur halbherzig.</p>
<p>Und ja, statische Member musst du nochmals in der Sourcedatei definieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2253956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2253956</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 24 Sep 2012 13:13:17 GMT</pubDate></item><item><title><![CDATA[Reply to Resize eines static vector aus einem externen struct on Mon, 24 Sep 2012 14:00:50 GMT]]></title><description><![CDATA[<p>Ich versuche mal zu beschreiben, was ich eigentlich erreichen will und warum ich das mache.<br />
Im header habe ich im struct TrajectoryplannerInData verschiedene member. Hier im Beispiel habe ich die anderen rausgeworfen, so dass nur freespace übrig bleibt. Die Variable SplineControlPoints stellt für mich im weiteren Verlauf eine Art Zwischenvariable dar.<br />
Im Sourcefile übergebe ich dann die Kontrollpunkte über die SplineControlPoints an die Variable ControlPoints. Eventuell könnte ich auch den Zwischenschritt weglassen.<br />
Mir ist bewusst, dass der Code noch falsch ist, aber ich denke mal, somit wisst ihr warum ich das mache. <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">//header
using namespace std;

extern struct STrajectoryplannerInData TrajectoryplannerInData;

struct SFreespace
{
	static std::vector&lt;float2&gt; SplineControlPoints;

	};

struct STrajectoryplannerInData
{

  SFreespace	freespace;

};

//source
#include &quot;TrajectoryplannerIn.h&quot;
namespace task2Trajectoryplanner
{
void write2InputStructure(const CFreespaceDataChannelMsg		 &amp; fs )
{

		int ControlPointCount = fs.SplineControlPoints.mBufferDataSize/sizeof(float2);

		static std::vector&lt;float2&gt; ControlPoints;

TrajectoryplannerInData.freespace.SplineControlPoints.resize(ControlPointCount);

		memcpy(&amp;ControlPoints.front(), fs.SplineControlPoints.mBuffer, ControlPoints.size()*sizeof(float2));
		TrajectoryplannerInData.freespace.SplineControlPoints=ControlPoints;

		}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2253964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2253964</guid><dc:creator><![CDATA[eric84]]></dc:creator><pubDate>Mon, 24 Sep 2012 14:00:50 GMT</pubDate></item></channel></rss>