<?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[Protected&#x2F;Private static Variablen?]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>wie kann ich die static Variablen in diesem Beispiel protected/private machen? (Nur für den Setter zugänglich.)<br />
Ich möchte die static Var nicht unbedingt innerhalb der Funktion aufbewahren.</p>
<pre><code class="language-cpp">class ABCD {
public:
//protected:
	static std::string s_sAAAA;

	static void SetAAAA(const std::string &amp;sAAAA) {
		s_sAAAA=sAAAA;
	}	
};

std::string ABCD::s_sAAAA=&quot;&quot;;

int main(int argc, char* argv[]) {
	ABCD::SetAAAA(&quot;a&quot;);
	if (ABCD::s_sAAAA.length()&gt;0) {
		printf(&quot;2&quot;);
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/190492/protected-private-static-variablen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 15:26:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/190492.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Aug 2007 12:27:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:27:11 GMT]]></title><description><![CDATA[<p>Hallo Forum,</p>
<p>wie kann ich die static Variablen in diesem Beispiel protected/private machen? (Nur für den Setter zugänglich.)<br />
Ich möchte die static Var nicht unbedingt innerhalb der Funktion aufbewahren.</p>
<pre><code class="language-cpp">class ABCD {
public:
//protected:
	static std::string s_sAAAA;

	static void SetAAAA(const std::string &amp;sAAAA) {
		s_sAAAA=sAAAA;
	}	
};

std::string ABCD::s_sAAAA=&quot;&quot;;

int main(int argc, char* argv[]) {
	ABCD::SetAAAA(&quot;a&quot;);
	if (ABCD::s_sAAAA.length()&gt;0) {
		printf(&quot;2&quot;);
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1350417</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350417</guid><dc:creator><![CDATA[martin_salo]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:27:11 GMT</pubDate></item><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:30:14 GMT]]></title><description><![CDATA[<p>Und wo ist die Frage? Private static's kannst/musst du genauso deklarieren wie öffentliche, allerdings kommst du außerhalb der Member nicht mehr an die Variablen dran (d.h. die main() kann nicht mehr den Inhalt von ABCD::s_sAAAA auslesen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350421</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:30:14 GMT</pubDate></item><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:31:15 GMT]]></title><description><![CDATA[<p>Ähmm... einfach die Variable protected/private deklarieren und die Setter public machen...</p>
<pre><code class="language-cpp">class ABCD
{
  protected:
    static std::string s_sAAAA;
  public:
    static void SetAAAA(const std::string &amp;sAAAA) {
      s_sAAAA=sAAAA;
    }	
};
...
</code></pre>
<p>cu André</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350423</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350423</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:33:14 GMT]]></title><description><![CDATA[<p>Die Fehlermeldung von asc Code ist:</p>
<blockquote>
<p>error C2248: 's_sAAAA' : cannot access protected member declared in class 'ABCD'</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1350428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350428</guid><dc:creator><![CDATA[martin_salo]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:33:14 GMT</pubDate></item><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:35:53 GMT]]></title><description><![CDATA[<p>martin_salo schrieb:</p>
<blockquote>
<p>Die Fehlermeldung von asc Code ist:</p>
<blockquote>
<p>error C2248: 's_sAAAA' : cannot access protected member declared in class 'ABCD'</p>
</blockquote>
</blockquote>
<pre><code class="language-cpp">int main(int argc, char* argv[]) 
{
    ABCD::SetAAAA(&quot;a&quot;);

    if (ABCD::GetsAAAA().length() &gt; 0) 
    {
        printf(&quot;2&quot;);
    }
    return 0;
}
</code></pre>
<p>Schreib dir einfach einen Getter der wie SetAAA arbeitet (nur das er halt die Variable zurückgibt).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1350435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350435</guid><dc:creator><![CDATA[Chris++ 0]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:35:53 GMT</pubDate></item><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:38:49 GMT]]></title><description><![CDATA[<p>Mein Fehler. Danke <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1350443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350443</guid><dc:creator><![CDATA[martin_salo]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:38:49 GMT</pubDate></item><item><title><![CDATA[Reply to Protected&#x2F;Private static Variablen? on Thu, 23 Aug 2007 12:44:22 GMT]]></title><description><![CDATA[<p>Um nicht als Vollschuß zu gelten: Ich habe das BSP aus einem größeren Zusammenhang heraushgelöst:</p>
<pre><code class="language-cpp">class ABCD {
  protected:
    static std::string s_sAAAA;
  public:
    static void SetAAAA(const std::string &amp;sAAAA) {
      s_sAAAA=sAAAA;
    }   
}; 

static void SetAAAA(const std::string &amp;sAAAA) {
  s_sAAAA=sAAAA; // Diese ging nicht, weil ich eine Zeile höher den ABCD:: Prefix vergessen hatte. Deshalb dachte ich Statics dürften nur public sein.
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1350454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1350454</guid><dc:creator><![CDATA[martin_salo]]></dc:creator><pubDate>Thu, 23 Aug 2007 12:44:22 GMT</pubDate></item></channel></rss>