<?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[Zugriffsbereiche von Klassen (Anfängerfrage)]]></title><description><![CDATA[<p>Ich habe folgendes Problem:</p>
<pre><code class="language-cpp">class BigClass
{
 public:
    void AnyMethod(void);

 protected:
    SmallClass smallclass;
    OtherClass otherclass;
}

class OtherClass
{
 public:
    void AnotherMethod(void);
}

int main()
{
 BigClass bigclass;
 return 0;
}
</code></pre>
<p>So und nun will eine der Methoden von smallclass auf</p>
<p>a) bigclass.AnyMethod() und<br />
b) auf otherclass.AnotherMethod()</p>
<p>zugreifen. smallclass und otherclass sollen aber <em>protected</em> bleiben. Wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/214053/zugriffsbereiche-von-klassen-anfängerfrage</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 15:45:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/214053.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 May 2008 08:19:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 08:19:25 GMT]]></title><description><![CDATA[<p>Ich habe folgendes Problem:</p>
<pre><code class="language-cpp">class BigClass
{
 public:
    void AnyMethod(void);

 protected:
    SmallClass smallclass;
    OtherClass otherclass;
}

class OtherClass
{
 public:
    void AnotherMethod(void);
}

int main()
{
 BigClass bigclass;
 return 0;
}
</code></pre>
<p>So und nun will eine der Methoden von smallclass auf</p>
<p>a) bigclass.AnyMethod() und<br />
b) auf otherclass.AnotherMethod()</p>
<p>zugreifen. smallclass und otherclass sollen aber <em>protected</em> bleiben. Wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516145</guid><dc:creator><![CDATA[c++Beginner]]></dc:creator><pubDate>Sun, 25 May 2008 08:19:25 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 08:31:56 GMT]]></title><description><![CDATA[<p>Einfach machen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516151</guid><dc:creator><![CDATA[ääääääöü]]></dc:creator><pubDate>Sun, 25 May 2008 08:31:56 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 08:35:34 GMT]]></title><description><![CDATA[<p>Probiers halt aus bevor du solche Fragen stellst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /><br />
Da anyMethod und anotherMethod als public deklariert ist kann die jeder und alles benutzen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516152</guid><dc:creator><![CDATA[zzZZZzz]]></dc:creator><pubDate>Sun, 25 May 2008 08:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 09:38:18 GMT]]></title><description><![CDATA[<p>ääääääöü schrieb:</p>
<blockquote>
<p>Einfach machen</p>
</blockquote>
<p>zzZZZzz schrieb:</p>
<blockquote>
<p>Probiers halt aus bevor du solche Fragen stellst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Bevor ihr euch so genial vorkommt, solltet ihr die Problemstellung noch einmal überdenken. <code>otherclass</code> ist in diesem Kontext protected, deshalb ist ein Zugriff von aussen nicht möglich. Auch die Tatsache, dass sich <code>smallclass</code> in der gleichen Klasse ( <code>bigclass</code> ) wie <code>otherclass</code> befindet, ändert nichts an der Zugriffsberechtigung.</p>
<p>Du könntest das mit <code>friend</code> lösen, um spezifischen Zugriff zu erlauben.</p>
<p>Du hast auch einige formale Fehler und Unschönheiten bzw. überflüssigen Code:</p>
<pre><code class="language-cpp">class BigClass
{
   // ...
};  // Hier kommt ein Strichpunkt (bei den anderen Klassenblöcken auch)!

void AnotherMethod(void); // Bei Funktionen ohne Parameter musst du kein void in die Klammern schreiben.

int main()
{
 return 0;  // Ist auch überflüssig, main() gibt standardmässig 0 zurück.
}
</code></pre>
<p>Ausserdem würde ich mir den ganzen Aufbau noch einmal überlegen.<br />
OtherClass ist zu dem Zeitpunkt, wo es als Member in BigClass vorkommt, noch nicht definiert. Wie willst du auf bigclass zugreifen, wenn davon noch keine Instanz vorkommt (oder wo ist SmallClass definiert)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516174</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516174</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 25 May 2008 09:38:18 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 12:26:26 GMT]]></title><description><![CDATA[<p>Eine weitere Möglichkeit wäre das über eine Hilfsfunktiokn von BigClass zu lösen, welche dir die Funktionen aufruft, die du willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516278</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 25 May 2008 12:26:26 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 13:36:47 GMT]]></title><description><![CDATA[<p>das system ist eigendlich ganz einfach</p>
<p>public lässt zugriffe von allem und jedem zu<br />
private blockt alles ab, ausser eine memberfunktion greift auf private variablen und funktion zu<br />
protected ist wie private, nur dass bei vererbung die protected sachen in der abgeleiteten klasse auch private sind und nicht wie bei private unsichtbar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516335</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 25 May 2008 13:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Sun, 25 May 2008 14:00:34 GMT]]></title><description><![CDATA[<p>... also ich möchte aus meiner txt datei nicht alles im programm sehn nur ein paar zeichen aus der textdatei wie kireg ich das hin dass ich das hin???<br />
also ich kann euch zeigen was ich schon gemacht habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> :::</p>
<p>#include &lt;conio.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;string.h&gt;<br />
#include &lt;windows.h&gt;<br />
#include &lt;math.h&gt;</p>
<p>main ()<br />
{<br />
char hp[20], string[80], pfad[]=&quot; &gt; C:\\programm.txt&quot;;<br />
int i,laenge;</p>
<p>printf(&quot;Geben Sie die gew\x81nschte internet Adresse ein: &quot;);<br />
gets(hp);</p>
<p>strcpy(string, &quot;ping &quot;);<br />
strcat(string, hp);<br />
strcat(string, pfad);<br />
system(string);</p>
<p>//printf(&quot;( g %s);&quot;,hp);</p>
<p>laenge = strlen(hp);</p>
<p>/* ifstream voc_stream(&quot;C:\\programm.txt&quot;);<br />
vector&lt;string&gt; lines;<br />
string temp;<br />
while(getline(voc_stream, temp))<br />
{<br />
lines.push_back(temp);<br />
}<br />
*/</p>
<p>getch();<br />
}</p>
<p>nur das klappt i wie nich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> ... ich versteh auch nich warum <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> ... und ich glaube wennsch das so mache dann kriegsch die ganze textdatei da rein aber wie gesagt ich will nur ein paar zeichen haben...</p>
<p>die textdatei sieht im moment so aus und wird ständig verändert::</p>
<p>Ping <a href="http://www.l.google.com" rel="nofollow">www.l.google.com</a> [<strong>74.125.39.103</strong>] mit 32 Bytes Daten:</p>
<p>Zeitberschreitung der Anforderung.</p>
<p>Zeitberschreitung der Anforderung.</p>
<p>Zeitberschreitung der Anforderung.</p>
<p>und das was in &quot;[...]&quot; ist will ich in meinem programm haben... also das programm soll ungefähr so aussehn:</p>
<p>Bitte geben sie ihre Adresse an: // dann gibt man die die adresse an z.B. <a href="http://www.google.de" rel="nofollow">www.google.de</a></p>
<p>die IP der angegebenen adresse lautet: // die einfügung aus der textdatei</p>
<p>könnte mir einer bitte helfen?? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516352</guid><dc:creator><![CDATA[DonFlippy]]></dc:creator><pubDate>Sun, 25 May 2008 14:00:34 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Wed, 28 May 2008 18:19:00 GMT]]></title><description><![CDATA[<p>Danke für eure Hilfe.<br />
Angenommen, ich deklariere in BigClass smallclass und otherclass auch als public, mit den bereinigten Fehlern etwa so:</p>
<pre><code>class OtherClass
{
 public:
    void AnotherMethod(void);
};

class SmallClass
{
 public:
    void CallMethod(void)
    {
     // Was muss hier stehen? Einfach otherclass.AnotherMethod();?
    }
};

class BigClass
{
 public:
    void AnyMethod(void);
    SmallClass smallclass;
    OtherClass otherclass;
};

int main()
{
 BigClass bigclass;
}
</code></pre>
<p>Kann ich jetzt in smallclass.CallMethod() einfach otherclass.AnotherMethod mit gleichnamigem Befehl aufrufen?</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19864">@DonFlippy</a>: Öffne mal ein neues Thema, bevor du hier mit einer völlig anderen Frage einfach reinplatzt!! Und übrigens: Zur Markierung von</p>
<pre><code>Code
</code></pre>
<p>dient der Befehl &quot;code&quot; in eckigen Klammern oder die gleichnamige Schaltfläche.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1518652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1518652</guid><dc:creator><![CDATA[c++Beginner]]></dc:creator><pubDate>Wed, 28 May 2008 18:19:00 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriffsbereiche von Klassen (Anfängerfrage) on Wed, 28 May 2008 18:22:23 GMT]]></title><description><![CDATA[<p>Oben meinte ich otherclass.AnotherMethod() mit Klammern. Anscheinend gibts hier keinen edit-Befehl. Ach so, als Unregistrierter... Stimmt. Egal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1518656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1518656</guid><dc:creator><![CDATA[c++Beginner]]></dc:creator><pubDate>Wed, 28 May 2008 18:22:23 GMT</pubDate></item></channel></rss>