<?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[Ist private aber kann trotzdem aufgerufen werden]]></title><description><![CDATA[<p>So meine Frage ist, in Zeile 24 und 25 des Codes da ist &quot;Object.Zahl_a&quot; und &quot;Object.Zahl_b&quot;, so beide sind private, ich kann sie aber trotzdem fehlerlos aufrufen? Warum? Wie im Code mit Kommentar schon angedeutet hätte ich es eigentlich mit einer &quot;GetZahl_a&quot; und &quot;GetZahl_b&quot; Funktion gemacht, aber es geht auch ohne? Also irgendwie hab ich grad nen Denkfehler, aber mein Buch besagt private Variablen kann man nur innnerhalb der Klasse bzw. mit den jeweiligen Methoden der Klasse aufrufen. Und ich finde das &quot;Object.Zahl_a&quot; und &quot;Object.Zahl_b&quot; klar und deutlich private sind, sie werden zwar in einer Methode einer Klasse aufgerufen aber das ist ja nicht ihre eigene Methode blablabalba.... also irgendwie steh ich auf der Leitung? Bitte um Aufklärung.<br />
Dankeschön schon mal im Voraus.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class math
{
    public:
    math(int Zahl_a,int Zahl_b);
    math MultYourselfWith(math Object);
    int GetZahl_a() {return Zahl_a;}
    int GetZahl_b() {return Zahl_b;}
    private:
    int Zahl_a;
    int Zahl_b;
};

math::math(int Zahl_a,int Zahl_b)
:Zahl_a(Zahl_a),Zahl_b(Zahl_b)
{

}

math math::MultYourselfWith(math Object)
{
    int temp_a = Zahl_a * Object.Zahl_a;   //Object.GetZahl_a();     Object.Zahl_a ist doch private?
    int temp_b = Zahl_b * Object.Zahl_b;   //Object.GetZahl_b();     Object.Zahl_b ist doch private?
    math result(temp_a,temp_b);
    return result;
}

int main()
{
    math A(5,7);
    math B(8,5);
    math C = A.MultYourselfWith(B);
    cout &lt;&lt; C.GetZahl_a() &lt;&lt; &quot;\n&quot; &lt;&lt; C.GetZahl_b() &lt;&lt; &quot;\n&quot;;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/171681/ist-private-aber-kann-trotzdem-aufgerufen-werden</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 12:17:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171681.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Jan 2007 12:12:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ist private aber kann trotzdem aufgerufen werden on Sun, 28 Jan 2007 12:12:44 GMT]]></title><description><![CDATA[<p>So meine Frage ist, in Zeile 24 und 25 des Codes da ist &quot;Object.Zahl_a&quot; und &quot;Object.Zahl_b&quot;, so beide sind private, ich kann sie aber trotzdem fehlerlos aufrufen? Warum? Wie im Code mit Kommentar schon angedeutet hätte ich es eigentlich mit einer &quot;GetZahl_a&quot; und &quot;GetZahl_b&quot; Funktion gemacht, aber es geht auch ohne? Also irgendwie hab ich grad nen Denkfehler, aber mein Buch besagt private Variablen kann man nur innnerhalb der Klasse bzw. mit den jeweiligen Methoden der Klasse aufrufen. Und ich finde das &quot;Object.Zahl_a&quot; und &quot;Object.Zahl_b&quot; klar und deutlich private sind, sie werden zwar in einer Methode einer Klasse aufgerufen aber das ist ja nicht ihre eigene Methode blablabalba.... also irgendwie steh ich auf der Leitung? Bitte um Aufklärung.<br />
Dankeschön schon mal im Voraus.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class math
{
    public:
    math(int Zahl_a,int Zahl_b);
    math MultYourselfWith(math Object);
    int GetZahl_a() {return Zahl_a;}
    int GetZahl_b() {return Zahl_b;}
    private:
    int Zahl_a;
    int Zahl_b;
};

math::math(int Zahl_a,int Zahl_b)
:Zahl_a(Zahl_a),Zahl_b(Zahl_b)
{

}

math math::MultYourselfWith(math Object)
{
    int temp_a = Zahl_a * Object.Zahl_a;   //Object.GetZahl_a();     Object.Zahl_a ist doch private?
    int temp_b = Zahl_b * Object.Zahl_b;   //Object.GetZahl_b();     Object.Zahl_b ist doch private?
    math result(temp_a,temp_b);
    return result;
}

int main()
{
    math A(5,7);
    math B(8,5);
    math C = A.MultYourselfWith(B);
    cout &lt;&lt; C.GetZahl_a() &lt;&lt; &quot;\n&quot; &lt;&lt; C.GetZahl_b() &lt;&lt; &quot;\n&quot;;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1218533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218533</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Sun, 28 Jan 2007 12:12:44 GMT</pubDate></item><item><title><![CDATA[Reply to Ist private aber kann trotzdem aufgerufen werden on Sun, 28 Jan 2007 12:20:55 GMT]]></title><description><![CDATA[<p>private bezieht sich auf Klasse und nicht auf Objekte. Klasse != Objekt. Machts jetzt klick? <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>
<p>math::MultYourselfWith und Objekt.zahl_a sind beide vom Typ math, also ist der Zugriff i.O.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218537</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Sun, 28 Jan 2007 12:20:55 GMT</pubDate></item><item><title><![CDATA[Reply to Ist private aber kann trotzdem aufgerufen werden on Sun, 28 Jan 2007 12:21:45 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>In den Funktionen der Klasse kannst du natürlich auch uaf die private bzw, protected Varaiblen zugreifen. Zuwas würde man die denn sonst brauchen?</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218538</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 28 Jan 2007 12:21:45 GMT</pubDate></item><item><title><![CDATA[Reply to Ist private aber kann trotzdem aufgerufen werden on Mon, 29 Jan 2007 00:24:54 GMT]]></title><description><![CDATA[<p>Jo, das ist wieder das typische Misverständnis bei &quot;private&quot;.<br />
Ist ein beliebter Anfängerfehler zu glauben dass man aus einer Funktion Foo::Bar nicht auf private Members von _anderen_ Foo Instanzen zugreifen darf. Darf man aber <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1218942</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218942</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 29 Jan 2007 00:24:54 GMT</pubDate></item></channel></rss>