<?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[Zugriff auf Variable einer anderen Klasse]]></title><description><![CDATA[<p>Ok, absolutes Noob-Problem:</p>
<p>Ich möchte in einer Klasse auf eine Variable zugreifen, die ich in einer anderen Klasse definiert habe.</p>
<p>Pseudo-Code:</p>
<p>header.h</p>
<pre><code>class1
{
  String a_string;
};

class2
{
 ..
};
</code></pre>
<p>class1.cpp</p>
<pre><code>#include &quot;header.h&quot;

class1::class1()
{
  a_string = &quot;TEST&quot;;
}
</code></pre>
<p>class2.cpp</p>
<pre><code>#include &quot;header.h&quot;

class2::class2()
{
  cout &lt;&lt; a_string;
}
</code></pre>
<p>Die Ausgabe in class2 bleibt leer. Wie kommt class2 an a_string?</p>
<p>batzilla</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/182219/zugriff-auf-variable-einer-anderen-klasse</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 17:22:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182219.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 May 2007 19:20:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zugriff auf Variable einer anderen Klasse on Tue, 22 May 2007 19:20:38 GMT]]></title><description><![CDATA[<p>Ok, absolutes Noob-Problem:</p>
<p>Ich möchte in einer Klasse auf eine Variable zugreifen, die ich in einer anderen Klasse definiert habe.</p>
<p>Pseudo-Code:</p>
<p>header.h</p>
<pre><code>class1
{
  String a_string;
};

class2
{
 ..
};
</code></pre>
<p>class1.cpp</p>
<pre><code>#include &quot;header.h&quot;

class1::class1()
{
  a_string = &quot;TEST&quot;;
}
</code></pre>
<p>class2.cpp</p>
<pre><code>#include &quot;header.h&quot;

class2::class2()
{
  cout &lt;&lt; a_string;
}
</code></pre>
<p>Die Ausgabe in class2 bleibt leer. Wie kommt class2 an a_string?</p>
<p>batzilla</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1290129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1290129</guid><dc:creator><![CDATA[batzilla]]></dc:creator><pubDate>Tue, 22 May 2007 19:20:38 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Variable einer anderen Klasse on Tue, 22 May 2007 19:25:57 GMT]]></title><description><![CDATA[<p>was soll das für nen sinn haben? Membervariablen sind für die Klasse zu der sie gehören und nicht für eine andere. Du kannst getter und setter Funktionen schreiben, wenn du das brauchst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1290130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1290130</guid><dc:creator><![CDATA[sinnsucher]]></dc:creator><pubDate>Tue, 22 May 2007 19:25:57 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Variable einer anderen Klasse on Wed, 23 May 2007 07:13:01 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Du kannst class2 im Konstruktor eine Instanz von class1 mitgeben und dann auf die Membervariable zugreifen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1290338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1290338</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 23 May 2007 07:13:01 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Variable einer anderen Klasse on Wed, 23 May 2007 07:40:45 GMT]]></title><description><![CDATA[<p>Vielleicht nützt dir auch das Stichwort <strong>friend</strong> etwas...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1290356</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1290356</guid><dc:creator><![CDATA[zeigerzeiger]]></dc:creator><pubDate>Wed, 23 May 2007 07:40:45 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Variable einer anderen Klasse on Wed, 23 May 2007 08:05:09 GMT]]></title><description><![CDATA[<p>Eine Klasse klasse kann bleibig oft instanziert werden, unter anderem auch kein einizeges Mal. Welches a_String soll denn deiner Meinung nach verwendet werden?</p>
<p>Beispiel 1:</p>
<pre><code class="language-cpp">class1 foo;
class1 bar;
class1 baz;

class2 qux; // welches a_string soll hier benutzt werden? foo.a_string? oder bar.a_string? oder vielleicht doch lieber baz.a_string?
</code></pre>
<p>Beispiel 2:</p>
<pre><code class="language-cpp">class2 qux; // welches a_string soll hier benutzt werden? es existiert doch gar keins
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1290370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1290370</guid><dc:creator><![CDATA[Helium]]></dc:creator><pubDate>Wed, 23 May 2007 08:05:09 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf Variable einer anderen Klasse on Wed, 23 May 2007 12:25:14 GMT]]></title><description><![CDATA[<p>? Vllt. das?</p>
<pre><code class="language-cpp">class a
{
public:
    a() : m_member(&quot;Test&quot;) {}
    ~a();

protected:
    std::wstring m_member;
};

class b : public a
{
    void stream(std::ostream&amp; ss) const { ss &lt;&lt; m_member &lt;&lt; std::endl; }
};
</code></pre>
<p>...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1290639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1290639</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Wed, 23 May 2007 12:25:14 GMT</pubDate></item></channel></rss>