Operator overloading by using friend function!

I'm having trouble working on my data structure programming project!!
I have to implement the statistician class but the operator overloading part is a problem!!
This is the header file!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

namespace main_savitch_2C
{
    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& s1, const statistician& s2);
        friend statistician operator *
            (double scale, const statistician& 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& s1, const statistician& s2);
}

As you see in the header file, the operator function is defined with friend function!! The problem is in the implementation file!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include "stats.h"

using std::cout;
using std::cin;
using std::endl;

namespace main_savitch_2C{
	statistician::statistician(){
		count = 0;
		total = 0;

	}
	void statistician::next(double r){
		if(count ==0){
			tinyest = r;
			largest = r;
		}
		else if(count != 0){
			if(r < tinyest){
				tinyest = r;
			}
			else if(r > largest){
				largest = r;
			}
		}
		total += r;
		count++;
	}
	int statistician::length() const{
		return count;
	}
	double statistician::sum() const{
		return total;
	}
	double statistician::mean() const{
		return (total/count);
	}
	double statistician::minimum() const{
		return tinyest;
	}
	double statistician::maximum() const{
		return largest;
	}
	statistician statistician::operator + (const statistician& s1, const statistician& s2){
		statistician result;
		result.total = s1.total + s2.total;
		result.count = s1.count + s2.count;
		if(s1.tinyest <= s2.tinyest){
			result.tinyest = s1.tinyest;
		}
		else {
			result.tinyest = s2.tinyest;
		}
		if(s1.largest >= s2.largest){
			result.largest = s1.largest;
		}
		else {
			result.largest = s2.largest;
		}
		return result;
	}

}

The compiler keep saying the operator function need either zero or one parameter..!! Anyone knows what the problem is??
T.,T
Topic archived. No new replies allowed.