<?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[friend und non-member function]]></title><description><![CDATA[<p>hallo,</p>
<p>ich sollte diese klasse implementieren:</p>
<pre><code>namespace test_1
{
    class statistician
    {
    public:
        // CONSTRUCTOR
        statistician( );
        // MODIFICATION MEMBER FUNCTIONS
        void next(double r);
        void reset( );
        // CONSTANT MEMBER FUNCTIONS
        int length( ) const;
        double sum( ) const;
        double mean( ) const;
        double minimum( ) const;
        double maximum( ) const;
        // FRIEND FUNCTIONS
        friend statistician operator +
            (const statistician &amp; s1, const statistician &amp; s2);
        friend statistician operator *
            (double scale, const statistician &amp; s);
    private:
        int count;       // How many numbers in the sequence
        double total;    // The sum of all the numbers in the sequence
        double tinyest;  // The smallest number in the sequence
        double largest;  // The largest number in the sequence
    };

    // NON-MEMBER functions for the statistician class
    bool operator ==(const statistician&amp; s1, const statistician&amp; s2);
}
</code></pre>
<p>Nur ist mir nicht ganz klar, was der unterschied der friend und non-member function (operator ==) zu den normalen member function in diesem header file ist bzw. wie ich diese im implmentation file dann definieren muss...? <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="😕"
    /></p>
<p>kann mir hier jemand weiterhelfen?</p>
<p>lg matti</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/158836/friend-und-non-member-function</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 02:20:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/158836.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Sep 2006 19:53:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to friend und non-member function on Fri, 08 Sep 2006 19:54:13 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>ich sollte diese klasse implementieren:</p>
<pre><code>namespace test_1
{
    class statistician
    {
    public:
        // CONSTRUCTOR
        statistician( );
        // MODIFICATION MEMBER FUNCTIONS
        void next(double r);
        void reset( );
        // CONSTANT MEMBER FUNCTIONS
        int length( ) const;
        double sum( ) const;
        double mean( ) const;
        double minimum( ) const;
        double maximum( ) const;
        // FRIEND FUNCTIONS
        friend statistician operator +
            (const statistician &amp; s1, const statistician &amp; s2);
        friend statistician operator *
            (double scale, const statistician &amp; s);
    private:
        int count;       // How many numbers in the sequence
        double total;    // The sum of all the numbers in the sequence
        double tinyest;  // The smallest number in the sequence
        double largest;  // The largest number in the sequence
    };

    // NON-MEMBER functions for the statistician class
    bool operator ==(const statistician&amp; s1, const statistician&amp; s2);
}
</code></pre>
<p>Nur ist mir nicht ganz klar, was der unterschied der friend und non-member function (operator ==) zu den normalen member function in diesem header file ist bzw. wie ich diese im implmentation file dann definieren muss...? <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="😕"
    /></p>
<p>kann mir hier jemand weiterhelfen?</p>
<p>lg matti</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1133950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1133950</guid><dc:creator><![CDATA[mathon]]></dc:creator><pubDate>Fri, 08 Sep 2006 19:54:13 GMT</pubDate></item><item><title><![CDATA[Reply to friend und non-member function on Fri, 08 Sep 2006 20:53:46 GMT]]></title><description><![CDATA[<p>Eine friend-Funktion ist keine Methode einer Klasse, darf aber dennoch auf alle Member der Klasse zugreifen.</p>
<pre><code class="language-cpp">class foo {
  int i;
public:
  friend int bar(foo const &amp;a);
};

int bar(foo const &amp;a) {
  return a.i;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1133966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1133966</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Fri, 08 Sep 2006 20:53:46 GMT</pubDate></item><item><title><![CDATA[Reply to friend und non-member function on Fri, 08 Sep 2006 22:10:15 GMT]]></title><description><![CDATA[<p>ah okay, danke! Habe jetzt mal nur den Rumpf testweise implementiert, aber wenn ich dann das testfile (stattest.cpp) ausführe werden ziemlich merkwürdige fehler geworfen:</p>
<p>Also mein header-file</p>
<pre><code>#ifndef STATS_H     // Prevent duplicate definition
#define STATS_H
#include &lt;iostream&gt;

namespace test_1
{
    class statistician
    {
    public:
        // CONSTRUCTOR
        statistician( );
        // MODIFICATION MEMBER FUNCTIONS
        void next(double r);
        void reset( );
        // CONSTANT MEMBER FUNCTIONS
        int length( ) const;
        double sum( ) const;
        double mean( ) const;
        double minimum( ) const;
        double maximum( ) const;
        // FRIEND FUNCTIONS
        friend statistician operator +
            (const statistician &amp; s1, const statistician &amp; s2);
        friend statistician operator *
            (double scale, const statistician &amp; s);
    private:
        int count;       // How many numbers in the sequence
        double total;    // The sum of all the numbers in the sequence
        double tinyest;  // The smallest number in the sequence
        double largest;  // The largest number in the sequence
    };

    // NON-MEMBER functions for the statistician class
    bool operator ==(const statistician&amp; s1, const statistician&amp; s2);
}

#endif
</code></pre>
<p>Hier die Implementation aber nur halt mal der Rumpf, da ich nur mal sehen möchte, ob das testfile überhaupt korrekt startet:</p>
<pre><code>#include &quot;stats.h&quot;

using namespace test_1;

statistician::statistician()
{

}

void statistician::next(double r)
{

}

int statistician::length() const
{
    return 0;
}

double statistician::sum() const
{
    return 0;
}

double statistician::mean() const
{
    return 0;
}

double statistician::minimum() const
{
    return 0;
}

double statistician::maximum() const
{
    return 0;
}

bool operator ==(const statistician&amp; s1, const statistician&amp; s2)
{
	return true;
}

statistician operator + (const statistician &amp; s1, const statistician &amp; s2)
{
	return s1;
}

statistician operator * (double scale, const statistician &amp; s)
{
	return s;
}
</code></pre>
<p>Und hier das Testfile:</p>
<pre><code>#include &lt;cctype&gt;    // Provides toupper
#include &lt;iomanip&gt;   // Provides setw to set the width of an output
#include &lt;iostream&gt;  // Provides cout, cin
#include &lt;cstdlib&gt;   // Provides EXIT_SUCCESS
#include &quot;stats.h&quot;

using namespace test_1;
using namespace std;

// PROTOTYPES of functions used in this test program:
void print_menu( );

char get_user_command( );

double get_number( );

void print_values(const statistician&amp; s);

int main( )
{
    statistician s1, s2, s3;  // Three statisticians for us to play with
    char choice;              // A command character entered by the user
    double x;                 // Value for multiplication x*s1

    cout &lt;&lt; &quot;Three statisticians s1, s2, and s3 are ready to test.&quot; &lt;&lt; endl;

    do
    {
        cout &lt;&lt; endl;
        print_menu( );
        choice = toupper(get_user_command( ));
        switch (choice)
        {
            case 'R': cout &lt;&lt; &quot;Which one should I reset (1, 2, 3) &quot; &lt;&lt; endl;
                      choice = get_user_command( );
                      switch (choice)
                      {
			  case '1': s1.reset( );
                                    break;
			  case '2': s2.reset( );
                                    break;
			  case '3': s3.reset( );
                                    break;
                      }
                      cout &lt;&lt; &quot;Reset activated for s&quot; &lt;&lt; choice &lt;&lt; &quot;.&quot; &lt;&lt; endl;
                      break;
            case '1': s1.next(get_number( ));
                      break;
            case '2': s2.next(get_number( ));
                      break;
            case '3': s3.next(get_number( ));
                      break;
            case 'T': cout &lt;&lt; &quot;The values are given in this table:&quot; &lt;&lt; endl;
                      cout &lt;&lt; &quot;        LENGTH       SUM&quot;
                           &lt;&lt; &quot;   MINIMUM      MEAN   MAXIMUM&quot; &lt;&lt; endl;
                      cout &lt;&lt; &quot;  s1&quot;;
                      print_values(s1);
                      cout &lt;&lt; &quot;  s2&quot;;
                      print_values(s2);
                      cout &lt;&lt; &quot;  s3&quot;;
                      print_values(s3);
                      break;
            case 'E': if (s1 == s2)
                          cout &lt;&lt; &quot;s1 and s2 are equal.&quot; &lt;&lt; endl;
                      else
                          cout &lt;&lt; &quot;s1 and s2 are not equal.&quot; &lt;&lt; endl;
                      break;
            case '+': s3 = s1 + s2;
                      cout &lt;&lt; &quot;s3 has been set to s1 + s2&quot; &lt;&lt; endl;
                      break;
            case '*': cout &lt;&lt; &quot;Please type a value for x: &quot;;
                      cin &gt;&gt; x;
                      s3 = x * s1;
                      cout &lt;&lt; &quot;s3 has been set to &quot; &lt;&lt; x &lt;&lt; &quot; * s1&quot; &lt;&lt; endl;
		      break;
            case 'Q': cout &lt;&lt; &quot;Ridicule is the best test of truth.&quot; &lt;&lt; endl;
                      break;
            default: cout &lt;&lt; choice &lt;&lt; &quot; is invalid. Sorry.&quot; &lt;&lt; endl;
        }
    }
    while ((choice != 'Q'));

    return EXIT_SUCCESS;

}

void print_menu( )
{
    cout &lt;&lt; endl;
    cout &lt;&lt; &quot;The following choices are available: &quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; R  Activate one of the reset( ) functions&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; 1  Add a new number to the 1st statistician s1&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; 2  Add a new number to the 2nd statistician s2&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; 3  Add a new number to the 3rd statistician s3&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; T  Print a table of values from the statisticians&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; E  Test whether s1 == s2&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; +  Set the third statistician s3 equal to s1 + s2&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; *  Set the third statistician s3 equal to x*s1&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot; Q  Quit this test program&quot; &lt;&lt; endl;
}

char get_user_command( )
// Library facilties used: iostream.h
{
    char command;

    cout &lt;&lt; &quot;Enter choice: &quot;;
    cin &gt;&gt; command; 

    return command;
}

double get_number( )
// Library facilties used: iostream.h
{
    double result;

    cout &lt;&lt; &quot;Please enter the next real number for the sequence: &quot;;
    cin  &gt;&gt; result;
    cout &lt;&lt; result &lt;&lt; &quot; has been read.&quot; &lt;&lt; endl;
    return result;
}

void print_values(const statistician&amp; s)
// Library facilties used: iostream.h
{
    cout &lt;&lt; setw(10) &lt;&lt; s.length( );
    cout &lt;&lt; setw(10) &lt;&lt; s.sum( );
    if (s.length( ) != 0)
    {
        cout &lt;&lt; setw(10) &lt;&lt; s.minimum( );
        cout &lt;&lt; setw(10) &lt;&lt; s.mean( );
        cout &lt;&lt; setw(10) &lt;&lt; s.maximum( );
    }
    else
        cout &lt;&lt; &quot;      none      none      none&quot;;
    cout &lt;&lt; endl;
}
</code></pre>
<p>Nur wenn ich dann das testfile ausführe kommen folgende Fehler:</p>
<pre><code>------ Build started: Project: Assignment1, Configuration: Debug Win32 ------
Compiling...
stattest.cpp
Linking...
stattest.obj : error LNK2019: unresolved external symbol &quot;class main_savitch_2C::statistician __cdecl main_savitch_2C::operator*(double,class main_savitch_2C::statistician const &amp;)&quot; (??Dmain_savitch_2C@@YA?AVstatistician@0@NABV10@@Z) referenced in function _main
stattest.obj : error LNK2019: unresolved external symbol &quot;class main_savitch_2C::statistician __cdecl main_savitch_2C::operator+(class main_savitch_2C::statistician const &amp;,class main_savitch_2C::statistician const &amp;)&quot; (??Hmain_savitch_2C@@YA?AVstatistician@0@ABV10@0@Z) referenced in function _main
stattest.obj : error LNK2019: unresolved external symbol &quot;bool __cdecl main_savitch_2C::operator==(class main_savitch_2C::statistician const &amp;,class main_savitch_2C::statistician const &amp;)&quot; (??8main_savitch_2C@@YA_NABVstatistician@0@0@Z) referenced in function _main
stattest.obj : error LNK2019: unresolved external symbol &quot;public: void __thiscall main_savitch_2C::statistician::reset(void)&quot; (?reset@statistician@main_savitch_2C@@QAEXXZ) referenced in function _main
C:\Dokumente und Einstellungen\matti\Eigene Dateien\Visual Studio 2005\Projects\Assignment1\Debug\Assignment1.exe : fatal error LNK1120: 4 unresolved externals
Build log was saved at &quot;file://c:\Dokumente und Einstellungen\matti\Eigene Dateien\Visual Studio 2005\Projects\Assignment1\Assignment1\Debug\BuildLog.htm&quot;
Assignment1 - 5 error(s), 0 warning(s)
</code></pre>
<p>Weiß hier irgendjemand weiter?? <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="😕"
    /></p>
<p>matti</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1133985</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1133985</guid><dc:creator><![CDATA[mathon]]></dc:creator><pubDate>Fri, 08 Sep 2006 22:10:15 GMT</pubDate></item><item><title><![CDATA[Reply to friend und non-member function on Fri, 08 Sep 2006 22:27:42 GMT]]></title><description><![CDATA[<p>Du hast den Prototyp einer Funktion/Methode deklariert, aber die Funktion/Methode selbst nicht definiert und trotzdem verwendet/aufgerufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1134012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1134012</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Fri, 08 Sep 2006 22:27:42 GMT</pubDate></item><item><title><![CDATA[Reply to friend und non-member function on Fri, 08 Sep 2006 22:35:51 GMT]]></title><description><![CDATA[<p>aja stimmt, die reset Methode hab ich vergessen, aber naja diese unresolved external symbol errors werden leider noch immer geworfen...? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>------ Build started: Project: Assignment1, Configuration: Debug Win32 ------<br />
Compiling...<br />
statsimpl.cpp<br />
Linking...<br />
stattest.obj : error LNK2019: unresolved external symbol &quot;class main_savitch_2C::statistician __cdecl main_savitch_2C::operator*(double,class main_savitch_2C::statistician const &amp;)&quot; (??Dmain_savitch_2C@@YA?AVstatistician@0@NABV10@@Z) referenced in function _main<br />
stattest.obj : error LNK2019: unresolved external symbol &quot;class main_savitch_2C::statistician __cdecl main_savitch_2C::operator+(class main_savitch_2C::statistician const &amp;,class main_savitch_2C::statistician const &amp;)&quot; (??Hmain_savitch_2C@@YA?AVstatistician@0@ABV10@0@Z) referenced in function _main<br />
stattest.obj : error LNK2019: unresolved external symbol &quot;bool __cdecl main_savitch_2C::operator==(class main_savitch_2C::statistician const &amp;,class main_savitch_2C::statistician const &amp;)&quot; (??8main_savitch_2C@@YA_NABVstatistician@0@0@Z) referenced in function _main<br />
C:\Dokumente und Einstellungen\matti\Eigene Dateien\Visual Studio 2005\Projects\Assignment1\Debug\Assignment1.exe : fatal error LNK1120: 3 unresolved externals<br />
Build log was saved at &quot;file://c:\Dokumente und Einstellungen\matti\Eigene Dateien\Visual Studio 2005\Projects\Assignment1\Assignment1\Debug\BuildLog.htm&quot;<br />
Assignment1 - 4 error(s), 0 warning(s)<br />
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1134018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1134018</guid><dc:creator><![CDATA[mathon]]></dc:creator><pubDate>Fri, 08 Sep 2006 22:35:51 GMT</pubDate></item><item><title><![CDATA[Reply to friend und non-member function on Fri, 08 Sep 2006 23:56:20 GMT]]></title><description><![CDATA[<p>Ich komm da einfach nicht darauf, woher diese blöden unresolved external symbol erros herkommen....?? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1134061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1134061</guid><dc:creator><![CDATA[mathon]]></dc:creator><pubDate>Fri, 08 Sep 2006 23:56:20 GMT</pubDate></item></channel></rss>