<?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[Struct global]]></title><description><![CDATA[<pre><code>struct S {
};

A::Methode1
S fill;

B::Method2
auf Structur zugreifen
</code></pre>
<p>Wie kann ich eine struct innerhalb verschiedener Methoden global nutzen?<br />
Irgendwo hab ich von const S data; gelesen, dass liefert aber nur Nullen in B::Method2.</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328277/struct-global</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 03:39:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328277.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Oct 2014 07:39:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 07:39:35 GMT]]></title><description><![CDATA[<pre><code>struct S {
};

A::Methode1
S fill;

B::Method2
auf Structur zugreifen
</code></pre>
<p>Wie kann ich eine struct innerhalb verschiedener Methoden global nutzen?<br />
Irgendwo hab ich von const S data; gelesen, dass liefert aber nur Nullen in B::Method2.</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420206</guid><dc:creator><![CDATA[Sunset]]></dc:creator><pubDate>Wed, 01 Oct 2014 07:39:35 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 08:13:34 GMT]]></title><description><![CDATA[<pre><code>struct S
{
};

S variable;

A::methode()
{
  void fill();
}

B::methode()
{
  void machWasMitVariable();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420209</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Wed, 01 Oct 2014 08:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 08:17:02 GMT]]></title><description><![CDATA[<p>Die Frage bitte nochmal wiederholen, aber in klar und deutlich. Lese unbedingt aufmerksam(!) die als wichtig markierten Threads, die sich auf diese Problematik beziehen.</p>
<p>Codebeispiele bitte entweder mit korrekter, verständlicher Syntax; oder, falls Pseudocode, ausführlich genug, dass man sie auch verstehen kann. Codetags korrekt benutzen, so dass es auch lesbar ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420211</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420211</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 01 Oct 2014 08:17:02 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 09:44:37 GMT]]></title><description><![CDATA[<pre><code>im Header definiert:
struct S
{
double d1
};

im .cpp definiert:

S data;

A::methode()
{
data.d1 = 10;
}

B::methode()
{
double testvar = data.d1;
}
</code></pre>
<p>Dies führt dazu, dass testvar 0 ist und nicht 10.</p>
<p>P.S. die Codeformatierung funktioniert bei mir nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420233</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420233</guid><dc:creator><![CDATA[Sunset]]></dc:creator><pubDate>Wed, 01 Oct 2014 09:44:37 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 09:54:48 GMT]]></title><description><![CDATA[<p>Sunset schrieb:</p>
<blockquote>
<p>Dies führt dazu, dass testvar 0 ist und nicht 10.</p>
</blockquote>
<p>Da wird ja auch nirgendwo eine der Funktionen aufgerufen.</p>
<p>Sunset schrieb:</p>
<blockquote>
<p>die Codeformatierung funktioniert bei mir nicht.</p>
</blockquote>
<p>Benutz die Buttons unter dem Editierfeld.<br />
Du kannst (und solltest) Deine Beiträge oben editieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420235</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 01 Oct 2014 09:54:48 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 11:10:07 GMT]]></title><description><![CDATA[<p>[quote=&quot;Furble Wurble&quot;][quote=&quot;Sunset&quot;]Dies führt dazu, dass testvar 0 ist und nicht 10.[/quote]Da wird ja auch nirgendwo eine der Funktionen aufgerufen.<br />
[/quote]<br />
Ok, aber das hab ich jetzt nicht explizit hingeschrieben. Beide Methoden werden nacheinander aufgerufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420255</guid><dc:creator><![CDATA[Sunset]]></dc:creator><pubDate>Wed, 01 Oct 2014 11:10:07 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 11:33:06 GMT]]></title><description><![CDATA[<p>Ein vollständiges Beispiel könnte so aussehen:</p>
<pre><code>#include &lt;iostream&gt;

struct S
{
  double d;
};

S data;

class A{
  public:
    void methode(){data.d = 10.0;}
};

class B{
  public:
    void methode(){double testvar = data.d; std::cout &lt;&lt; &quot;testvar: &quot; &lt;&lt; testvar;}
};

int main()
{
  A a;
  a.methode();

  B b;
  b.methode();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420259</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Wed, 01 Oct 2014 11:33:06 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 15:16:39 GMT]]></title><description><![CDATA[<p>Oder mit viel Liebe aufteilen: <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>// s.h
#ifndef S_H
#define S_H

struct S{
  double d1;
};

#endif
</code></pre>
<pre><code>// a.h
#ifndef A_H
#define A_H

struct A{
  void method();
};

#endif
</code></pre>
<pre><code>// a.cc
#include &quot;a.h&quot;
#include &quot;s.h&quot;

extern S data;

void A::method(){
  data.d1 = 10;
}
</code></pre>
<pre><code>// b.h
#ifndef B_H
#define B_H

struct B{
  void method();
};

#endif
</code></pre>
<pre><code>// b.cc
#include &lt;iostream&gt;

#include &quot;b.h&quot;
#include &quot;s.h&quot;

extern S data;

void B::method(){
  std::cout &lt;&lt; data.d1 &lt;&lt; std::endl;
}
</code></pre>
<pre><code>// main.cc
#include &quot;a.h&quot;
#include &quot;b.h&quot;
#include &quot;s.h&quot;

S data;

int main(){
  A a;
  a.method();
  B b;
  b.method();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2420289</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420289</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Wed, 01 Oct 2014 15:16:39 GMT</pubDate></item><item><title><![CDATA[Reply to Struct global on Wed, 01 Oct 2014 16:38:23 GMT]]></title><description><![CDATA[<p>Sunset schrieb:</p>
<blockquote>
<p>P.S. die Codeformatierung funktioniert bei mir nicht.</p>
</blockquote>
<p>Du hast BBCode ausgeschaltet. Entweder global in deinem Profil oder explizit für jeden deiner Beiträge. Das war eine schlechte Idee.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2420303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2420303</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 01 Oct 2014 16:38:23 GMT</pubDate></item></channel></rss>