This is what I am trying to do. I'm trying to add each member of f1 and f2 together. _m is the slope and _b is the y-intersept.
linear_function operator +
(const linear_function& f1, const linear_function& f2)
{
linear_function f;
f._m = f1._m + f2._m;
f._b = f1._b + f2._b;
return f;
}
But it says that the members are inaccessible. Here is the .h file.
#ifndef LINEAR_H
#define LINEAR_H
#include <iostream> // Provides ostream
namespace main_savitch_2
{
class linear_function
{
public:
// CONSTRUCTOR
linear_function(double _b = 0.0, double _m = 0.0);
// MODIFICATION MEMBER FUNCTIONS
void set(double _b, double _m);
// CONSTANT MEMBER FUNCTIONS
double eval(double x) const;
double root() const;
double slope() const;
double y_intersept() const;
// CONSTANT OPERATORS
double operator ( ) (double x) const;
private:
double _m, _b;
};
// NON-MEMBER BINARY OPERATORS
linear_function operator +
(const linear_function& f1, const linear_function& f2);
linear_function operator -
(const linear_function& f1, const linear_function& f2);
linear_function operator |
(const linear_function& f1, const linear_function& f2);
// NON-MEMBER OUTPUT FUNCTIONS
std::ostream& operator << (std::ostream& out, const linear_function& p);
}
#endif
I googled member vs nonmember operator overloading and made mine match what was shown. Not sure why I'm getting this error.