<?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[Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Programm welches eine kleine Kontoverwaltung darstellen soll. Nun soll eine Funktion drucke_kontoauszug auf die privaten Member der Klasse zugreifen. Also müsste ich diese Funktion doch in die Kontoverwaltung.cpp schreiben und in der Klasse die Funktion mit friend deklarieren, oder? THX</p>
<pre><code class="language-cpp">////////////////////Kontoverwaltung.cpp////////////////////
#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &quot;Konto.h&quot;
using namespace std;

int zahl;
float _Betrag;

int main()
{

    CKonto testkonto(123123, 5.0);
weiter:
    do
    {
    cout &lt;&lt; &quot;Kontoverwaltung&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Ihr Kontostand betraegt:  &quot;;
    testkonto.kontostand_lesen();
    cout &lt;&lt; &quot;1: Kontostand lesen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2: einzahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;3: auszahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;4: Kontoauszug drucken&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;0: Ende&quot; &lt;&lt; endl;

    cin &gt;&gt; zahl;

        switch(zahl)
        {
            case 1:
                cout &lt;&lt; &quot;Kontostand lesen&quot; &lt;&lt; endl;
                break;
            case 2:
                cout &lt;&lt; &quot;einzahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.einzahlen(_Betrag);
                break;
            case 3:
                cout &lt;&lt; &quot;auszahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.auszahlen(_Betrag);
                break;
            case 4:
                cout &lt;&lt; &quot;Kontoauszug drucken:&quot; &lt;&lt; endl;
                //void drucke_kontoauszug();
                void drucke_kontoauszug()
                {
                    cout  &lt;&lt; &quot;\nDatum: 15.04.2009&quot; &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontonummer:&quot; &lt;&lt; iKtoNr &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontostand:&quot; &lt;&lt; fKtoStand &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
                }

                //testkonto.drucke_kontoauszug();
            case 5:
                cout &lt;&lt; &quot;Ende&quot; &lt;&lt; endl;
                break;
        }
    }while(zahl != 0);

    _getch();

}

////////////////////Konto.cpp////////////////////
#include &quot;Konto.h&quot;
#include &lt;iostream&gt;
using namespace std;

CKonto::CKonto(void)
{
}

CKonto::~CKonto(void)
{
}

CKonto::CKonto(int _KtoNr, float _KtoStand)
{
    fKtoStand = 0;
    iKtoNr = _KtoNr;
    fKtoStand = _KtoStand;
}

void CKonto::kontostand_lesen()
{
    cout &lt;&lt; fKtoStand &lt;&lt; &quot; Euro&quot; &lt;&lt; endl;
}

void CKonto::einzahlen(float _Betrag)
{
    fKtoStand+=_Betrag;
}

void CKonto::auszahlen(float _Betrag)
{
    if(_Betrag &gt; fKtoStand)
        cout &lt;&lt; &quot;Nicht moeglich, Limit erreicht!\n&quot; &lt;&lt; endl;
    else
    {
    fKtoStand-=_Betrag;
    }
}

////////////////////Konto.h////////////////////
#ifndef KONTO_H
#define KONTO_H

#pragma once

class CKonto
{
public:
    CKonto(void);
    ~CKonto(void);
    CKonto(int, float);
    void kontostand_lesen();
    void einzahlen(float _Betrag);
    void auszahlen(float _Betrag);
    friend void drucke_kontoauszug();
private:
    float fKtoStand;
    int iKtoNr;

};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/238964/funktion-im-hauptprogramm-die-auf-private-member-der-klasse-zugreifen-kann</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 14:23:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/238964.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Apr 2009 17:57:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 17:57:06 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Programm welches eine kleine Kontoverwaltung darstellen soll. Nun soll eine Funktion drucke_kontoauszug auf die privaten Member der Klasse zugreifen. Also müsste ich diese Funktion doch in die Kontoverwaltung.cpp schreiben und in der Klasse die Funktion mit friend deklarieren, oder? THX</p>
<pre><code class="language-cpp">////////////////////Kontoverwaltung.cpp////////////////////
#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &quot;Konto.h&quot;
using namespace std;

int zahl;
float _Betrag;

int main()
{

    CKonto testkonto(123123, 5.0);
weiter:
    do
    {
    cout &lt;&lt; &quot;Kontoverwaltung&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Ihr Kontostand betraegt:  &quot;;
    testkonto.kontostand_lesen();
    cout &lt;&lt; &quot;1: Kontostand lesen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2: einzahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;3: auszahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;4: Kontoauszug drucken&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;0: Ende&quot; &lt;&lt; endl;

    cin &gt;&gt; zahl;

        switch(zahl)
        {
            case 1:
                cout &lt;&lt; &quot;Kontostand lesen&quot; &lt;&lt; endl;
                break;
            case 2:
                cout &lt;&lt; &quot;einzahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.einzahlen(_Betrag);
                break;
            case 3:
                cout &lt;&lt; &quot;auszahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.auszahlen(_Betrag);
                break;
            case 4:
                cout &lt;&lt; &quot;Kontoauszug drucken:&quot; &lt;&lt; endl;
                //void drucke_kontoauszug();
                void drucke_kontoauszug()
                {
                    cout  &lt;&lt; &quot;\nDatum: 15.04.2009&quot; &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontonummer:&quot; &lt;&lt; iKtoNr &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontostand:&quot; &lt;&lt; fKtoStand &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
                }

                //testkonto.drucke_kontoauszug();
            case 5:
                cout &lt;&lt; &quot;Ende&quot; &lt;&lt; endl;
                break;
        }
    }while(zahl != 0);

    _getch();

}

////////////////////Konto.cpp////////////////////
#include &quot;Konto.h&quot;
#include &lt;iostream&gt;
using namespace std;

CKonto::CKonto(void)
{
}

CKonto::~CKonto(void)
{
}

CKonto::CKonto(int _KtoNr, float _KtoStand)
{
    fKtoStand = 0;
    iKtoNr = _KtoNr;
    fKtoStand = _KtoStand;
}

void CKonto::kontostand_lesen()
{
    cout &lt;&lt; fKtoStand &lt;&lt; &quot; Euro&quot; &lt;&lt; endl;
}

void CKonto::einzahlen(float _Betrag)
{
    fKtoStand+=_Betrag;
}

void CKonto::auszahlen(float _Betrag)
{
    if(_Betrag &gt; fKtoStand)
        cout &lt;&lt; &quot;Nicht moeglich, Limit erreicht!\n&quot; &lt;&lt; endl;
    else
    {
    fKtoStand-=_Betrag;
    }
}

////////////////////Konto.h////////////////////
#ifndef KONTO_H
#define KONTO_H

#pragma once

class CKonto
{
public:
    CKonto(void);
    ~CKonto(void);
    CKonto(int, float);
    void kontostand_lesen();
    void einzahlen(float _Betrag);
    void auszahlen(float _Betrag);
    friend void drucke_kontoauszug();
private:
    float fKtoStand;
    int iKtoNr;

};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1697429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697429</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Fri, 17 Apr 2009 17:57:06 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 18:05:51 GMT]]></title><description><![CDATA[<p>Und wieso soll das nicht einfach eine Methode deiner Konto-Klasse werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697430</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697430</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Fri, 17 Apr 2009 18:05:51 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 18:05:56 GMT]]></title><description><![CDATA[<p>ja, nennt sich dann methode</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697431</guid><dc:creator><![CDATA[ja]]></dc:creator><pubDate>Fri, 17 Apr 2009 18:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 18:59:33 GMT]]></title><description><![CDATA[<p>Dies soll ausdrücklich eine Funktion sein und keine Methode der Klasse um das Verständnis zu fördern. Die Methode wäre ja über testkonto.drucke_kontoauszug(); mit passender implementierung, das hat geklappt, wie aber geht das mit einer Funktion. Hier die exakte Teil-Aufgabe:</p>
<p>Erstellen Sie eine Funktion void drucke_kontoauszug(??) und eine Methode<br />
void CKonto::drucke_kontoauszug(??).<br />
Welche Möglichkeiten gibt es, der Funktion Zugriff auf private Attribute<br />
zu verschaffen?<br />
Was sind Gemeinsamkeiten und was Unterschiede der beiden Lösungen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697453</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Fri, 17 Apr 2009 18:59:33 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 19:19:14 GMT]]></title><description><![CDATA[<p>muschelfinder schrieb:</p>
<blockquote>
<p>Dies soll ausdrücklich eine Funktion sein und keine Methode der Klasse um das Verständnis zu fördern.</p>
</blockquote>
<p>Meines Erachtens fördern solche Designbrüche aber nicht das Verständnis. <code>friend</code> sollte eigentlich nur sehr sehr selten vorkommen.</p>
<p>Von daher würde ich, wenn ich von aussen zugreifen wollte, entsprechende Get-Methoden in der Klasse bereitstellen. So muss man nicht mehr direkt auf private Member zugreifen, sondern hat gekapselten Zugriff, was sowieso sinnvoll ist.</p>
<p>Also sowas:</p>
<pre><code class="language-cpp">float CKonto::gib_kontostand() const
{
    return fKtoStand;
}

void drucke_kontoauszug(/* was könnte hier stehen? */)
{
    // verwende gib_kontostand() und noch zu implementierendes
    // gib_kontonummer(), um auf die Klasse zuzugreifen.
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1697478</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697478</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 17 Apr 2009 19:19:14 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 21:35:16 GMT]]></title><description><![CDATA[<p>Ich bin noch ganz am Anfang von C++ und checke die Zusammehänge irgendwie nicht. Eine Ausgabe habe ich ja schon einmal hinbekommen. Aber da sagte der Prof. wir sollen es um den Unterschied zu sehen per Funktion im Hauptprogramm machen.</p>
<p>So bekomme ich den Kontoauszug ausgegeben, was will der Prof nun genau sehen?</p>
<pre><code class="language-cpp">////////////////////Kontoverwaltung.cpp////////////////////
#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &quot;Konto.h&quot;
using namespace std;

int zahl;
float _Betrag;

int main()
{

    CKonto testkonto(123123, 5.0);
weiter:
    do
    {
    cout &lt;&lt; &quot;Kontoverwaltung&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Ihr Kontostand betraegt:  &quot;;
    testkonto.kontostand_lesen();
    cout &lt;&lt; &quot;1: Kontostand lesen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2: einzahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;3: auszahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;4: Kontoauszug drucken&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;0: Ende&quot; &lt;&lt; endl;

    cin &gt;&gt; zahl;

        switch(zahl)
        {
            case 1:
                cout &lt;&lt; &quot;Kontostand lesen&quot; &lt;&lt; endl;
                break;
            case 2:
                cout &lt;&lt; &quot;einzahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.einzahlen(_Betrag);

                break;
            case 3:
                cout &lt;&lt; &quot;auszahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.auszahlen(_Betrag);
                break;
            case 4:
                cout &lt;&lt; &quot;Kontoauszug drucken:&quot; &lt;&lt; endl;
                testkonto.drucke_kontoauszug();
            case 5:
                cout &lt;&lt; &quot;Ende&quot; &lt;&lt; endl;
                break;
        }
    }while(zahl != 0);

    _getch();

}

////////////////////Konto.cpp////////////////////
#include &quot;Konto.h&quot;
#include &lt;iostream&gt;
using namespace std;

CKonto::CKonto(void)
{
}

CKonto::~CKonto(void)
{
}

CKonto::CKonto(int _KtoNr, float _KtoStand)
{
    fKtoStand = 0;
    iKtoNr = _KtoNr;
    fKtoStand = _KtoStand;
}

void CKonto::kontostand_lesen()
{
    cout &lt;&lt; fKtoStand &lt;&lt; &quot; Euro&quot; &lt;&lt; endl;
}

void CKonto::einzahlen(float _Betrag)
{
    fKtoStand+=_Betrag;
}

void CKonto::auszahlen(float _Betrag)
{
    if(_Betrag &gt; fKtoStand)
        cout &lt;&lt; &quot;Nicht moeglich, Limit erreicht!\n&quot; &lt;&lt; endl;
    else
    {
    fKtoStand-=_Betrag;
    }
}

void CKonto::drucke_kontoauszug()
    {
        cout  &lt;&lt; &quot;\nDatum: 15.04.2009&quot; &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontonummer:&quot; &lt;&lt; iKtoNr &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontostand:&quot; &lt;&lt; fKtoStand &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
    }

////////////////////Konto.h////////////////////
#ifndef KONTO_H
#define KONTO_H

#pragma once

class CKonto
{
public:
    CKonto(void);
    ~CKonto(void);
    CKonto(int, float);
    void kontostand_lesen();
    void einzahlen(float _Betrag);
    void auszahlen(float _Betrag);
    void drucke_kontoauszug();
private:
    float fKtoStand;
    int iKtoNr;

};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1697564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697564</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Fri, 17 Apr 2009 21:35:16 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Fri, 17 Apr 2009 22:22:03 GMT]]></title><description><![CDATA[<p>muschelfinder schrieb:</p>
<blockquote>
<p>Dies soll ausdrücklich eine Funktion sein und keine Methode der Klasse um das Verständnis zu fördern. Die Methode wäre ja über testkonto.drucke_kontoauszug(); mit passender implementierung, das hat geklappt, wie aber geht das mit einer Funktion. Hier die exakte Teil-Aufgabe:</p>
<p>Erstellen Sie eine Funktion void drucke_kontoauszug(??) und eine Methode<br />
void CKonto::drucke_kontoauszug(??).<br />
Welche Möglichkeiten gibt es, der Funktion Zugriff auf private Attribute<br />
zu verschaffen?<br />
Was sind Gemeinsamkeiten und was Unterschiede der beiden Lösungen?</p>
</blockquote>
<p>Wenn du eh schon eine Memberfunktion drucke_kontoauszug() hast, kannst du in der globalen Funktion ja diese aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1697575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1697575</guid><dc:creator><![CDATA[issen1]]></dc:creator><pubDate>Fri, 17 Apr 2009 22:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 09:25:46 GMT]]></title><description><![CDATA[<p>Hi,<br />
vielen Dank!</p>
<p>So wie ich es jetzt in meinem letzten Beitrag habe, meinte der Prof., dass es so nicht gedacht gewesen sei. Ich check aber nicht wie ich es anders machen soll. Was meint er denn in der Aufgabenstellung? Irgendwas mit friend meine ich hätte er erwähnt.</p>
<p>Besten Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698039</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Sun, 19 Apr 2009 09:25:46 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 09:30:19 GMT]]></title><description><![CDATA[<p><a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-238604-and-highlight-is-.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-238604-and-highlight-is-.html</a><br />
Dein Prof. sollte sich echt Gedanken machen, ob er an der richtigen Stelle seine Arbeit tut.<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698041</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698041</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Sun, 19 Apr 2009 09:30:19 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 09:54:06 GMT]]></title><description><![CDATA[<p>Ja gut, er will uns wohl die Zusammenhänge näher bringen.</p>
<p>Wer kann mir denn nun etwas zu der Aufgabe selbst sagen. Versteht jemand, was er genau möchte? Es soll ja nicht so sein wie ich es gemacht habe!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698055</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Sun, 19 Apr 2009 09:54:06 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 12:46:55 GMT]]></title><description><![CDATA[<p>muschelfinder schrieb:</p>
<blockquote>
<p>Ja gut, er will uns wohl die Zusammenhänge näher bringen.</p>
</blockquote>
<p>Inem er euch den ganzen Scheiß machen lässt den man möglichst vermeiden sollte? Didaktisch absolute Katastrophe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698144</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698144</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Sun, 19 Apr 2009 12:46:55 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 13:02:56 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>muschelfinder schrieb:</p>
<blockquote>
<p>Ja gut, er will uns wohl die Zusammenhänge näher bringen.</p>
</blockquote>
<p>Inem er euch den ganzen Scheiß machen lässt den man möglichst vermeiden sollte? Didaktisch absolute Katastrophe.</p>
</blockquote>
<p>finde ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698146</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698146</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 19 Apr 2009 13:02:56 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 16:38:59 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>pumuckl schrieb:</p>
<blockquote>
<p>muschelfinder schrieb:</p>
<blockquote>
<p>Ja gut, er will uns wohl die Zusammenhänge näher bringen.</p>
</blockquote>
<p>Inem er euch den ganzen Scheiß machen lässt den man möglichst vermeiden sollte? Didaktisch absolute Katastrophe.</p>
</blockquote>
<p>finde ich nicht.</p>
</blockquote>
<p>und wieso nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698237</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698237</guid><dc:creator><![CDATA[volkard&#x27;s wife]]></dc:creator><pubDate>Sun, 19 Apr 2009 16:38:59 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 16:46:57 GMT]]></title><description><![CDATA[<p>Besten Dank für die vielen Meinungen. Konkrete Hilfe würde mir aber mehr weiter helfen.</p>
<p>Ich denke er mein es so, dass ich eine Funktion in Kontoverwaltung.cpp deklarieren soll und diese in der Konto.h mit friend deklariere.</p>
<p>also etwa so:</p>
<pre><code class="language-cpp">//Kontoverwaltung.cpp
.....
void drucke_kontoauszug()
{
cout &lt;&lt; iKtoNr;
}

//Konto.h
friend void drucke_kontoauszug()
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1698238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698238</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Sun, 19 Apr 2009 16:46:57 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 19:38:37 GMT]]></title><description><![CDATA[<p>Das friend muss in die Klassendeklaration</p>
<pre><code class="language-cpp">class CKonto
{
friend void drucke_kontoauszug()
public:
 //..
private:
 //..

};
</code></pre>
<p>Gleichzeitig solltest du dir überlegen woher deine Funktion drucke_kontoauszug() weiß von welchem Objekt es die Daten ausdrucken soll. Die Funktion bräuchte daher in meinen Augen noch einen Parameter. <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/1698318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698318</guid><dc:creator><![CDATA[Mitleid]]></dc:creator><pubDate>Sun, 19 Apr 2009 19:38:37 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Sun, 19 Apr 2009 19:56:09 GMT]]></title><description><![CDATA[<p>Mitleid schrieb:</p>
<blockquote>
<p>Die Funktion bräuchte daher in meinen Augen noch einen Parameter. <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>
</blockquote>
<p>und nen semikolon nach den klammern brauch sie auch noch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698328</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698328</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 19 Apr 2009 19:56:09 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Tue, 21 Apr 2009 04:40:29 GMT]]></title><description><![CDATA[<p>Das wäre die Lösung gewesen:</p>
<pre><code class="language-cpp">////////////////////Kontoverwaltung.cpp////////////////////
#include &lt;iostream&gt;
#include &lt;conio.h&gt;
#include &quot;Konto.h&quot;
using namespace std;

int zahl;
float _Betrag;

int main()
{

    CKonto testkonto(123123, 5.0);
weiter:
    do
    {
    cout &lt;&lt; &quot;Kontoverwaltung&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;Ihr Kontostand betraegt:  &quot;;
    testkonto.kontostand_lesen();
    cout &lt;&lt; &quot;1: Kontostand lesen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;2: einzahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;3: auszahlen&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;4: Kontoauszug drucken&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;0: Ende&quot; &lt;&lt; endl;

    cin &gt;&gt; zahl;

        switch(zahl)
        {
            case 1:
                cout &lt;&lt; &quot;Kontostand lesen&quot; &lt;&lt; endl;
                break;
            case 2:
                cout &lt;&lt; &quot;einzahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.einzahlen(_Betrag);

                break;
            case 3:
                cout &lt;&lt; &quot;auszahlen&quot; &lt;&lt; endl;
                cin &gt;&gt; _Betrag;
                testkonto.auszahlen(_Betrag);
                break;
            case 4:
                cout &lt;&lt; &quot;Kontoauszug drucken:&quot; &lt;&lt; endl;
                drucke_kontoauszug(testkonto);
                break;
            case 5:
                cout &lt;&lt; &quot;Ende&quot; &lt;&lt; endl;
                break;
        }
    }while(zahl != 0);

    _getch();

}

////////////////////Konto.cpp////////////////////
#include &quot;Konto.h&quot;
#include &lt;iostream&gt;
using namespace std;

CKonto::CKonto(void)
{
}

CKonto::~CKonto(void)
{
}

CKonto::CKonto(int _KtoNr, float _KtoStand)
{
    fKtoStand = 0;
    iKtoNr = _KtoNr;
    fKtoStand = _KtoStand;
}

void CKonto::kontostand_lesen()
{
    cout &lt;&lt; fKtoStand &lt;&lt; &quot; Euro&quot; &lt;&lt; endl;
}

void CKonto::einzahlen(float _Betrag)
{
    fKtoStand+=_Betrag;
}

void CKonto::auszahlen(float _Betrag)
{
    if(_Betrag &gt; fKtoStand)
        cout &lt;&lt; &quot;Nicht moeglich, Limit erreicht!\n&quot; &lt;&lt; endl;
    else
    {
    fKtoStand-=_Betrag;
    }
}

void drucke_kontoauszug(CKonto &amp;param_konto)
    {
        cout &lt;&lt; &quot;\nDatum: 20.04.2009&quot;;
        cout &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kto. Nr.:&quot; &lt;&lt; param_konto.iKtoNr;
        cout &lt;&lt; &quot;\n&quot; &lt;&lt; &quot;Kontostand:&quot; &lt;&lt; param_konto.fKtoStand &lt;&lt; endl &lt;&lt; endl;
    }                

////////////////////Konto.h////////////////////
#ifndef KONTO_H
#define KONTO_H

#pragma once

class CKonto
{
public:
    CKonto(void);
    ~CKonto(void);
    CKonto(int, float);
    void kontostand_lesen();
    void einzahlen(float _Betrag);
    void auszahlen(float _Betrag);
    friend void drucke_kontoauszug(CKonto &amp;param_konto);
private:
    float fKtoStand;
    int iKtoNr;

};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1698920</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698920</guid><dc:creator><![CDATA[muschelfinder]]></dc:creator><pubDate>Tue, 21 Apr 2009 04:40:29 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Tue, 21 Apr 2009 06:24:51 GMT]]></title><description><![CDATA[<p>Die globalen Variablen in der Main müssen nicht sein, pack das mit in die Main rein.Und ich hoffe das &quot;weiter:&quot; vor deinem &quot;do-while&quot; ist nur noch ein überbleibsel von einem goto, verwende bitte sowas nie wieder <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698943</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698943</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Tue, 21 Apr 2009 06:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion im Hauptprogramm, die auf private Member der Klasse zugreifen kann on Tue, 21 Apr 2009 08:23:51 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>pumuckl schrieb:</p>
<blockquote>
<p>muschelfinder schrieb:</p>
<blockquote>
<p>Ja gut, er will uns wohl die Zusammenhänge näher bringen.</p>
</blockquote>
<p>Inem er euch den ganzen Scheiß machen lässt den man möglichst vermeiden sollte? Didaktisch absolute Katastrophe.</p>
</blockquote>
<p>finde ich nicht.</p>
</blockquote>
<p>Und warum nicht? Der Prof konstruiert halbseidene Beispiele die mit friends gelöst werden sollen, obwohl es Alternativen gibt. Sein Ziel ist zwar, die Verwendung von friends beizubringen, aber was er damit vor allem beibringt ist &quot;wenn du einen Hack brauchst nimm einfach friend&quot;. friend ist die stärkste Abhängigkeit die es in C++ gibt, und daher sollte man die Nutzung von friends nach Möglichkeit vermeiden. Die Aufgabenstellung des Profs &quot;es geht auch anders, aber nimm auf jeden Fall friend&quot; untergräbt das, wenn auch vielleicht unbeabsichtigt. Deshalb didaktisch ziemlicher Müll. Wenn er ein Beispiel genommen hätte was tatsächlich nur mit friends zu regeln gewesen wäre, kein Problem.<br />
Beim vorliegenden Beispiel wäre es sehr viel klüger gewesen, die friend-Lösung vorzugeben und als Aufgabe zu schreiben &quot;Finden Sie eine Alternative um die friend-Deklaration zu vermeiden&quot;. Damit hat der Student zum Einen ein Beispiel wie eine friend-Deklaration aussehen kann, zum Anderen lernt er das wichtigste bei friends - nämlich sie zu vermeiden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1698999</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1698999</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 21 Apr 2009 08:23:51 GMT</pubDate></item></channel></rss>