#include<iostream>
#include<math.h>
class real
{
double value;
double error;
public:
real(const double,const double);
double get_value();
double get_error();
friend bool operator<=(const real&,const double);
};
real::real(const double val, const double err) : value(val), error(fabs(err)) {}
double real::get_value()
{
return value;
}
double real::get_error()
{
return error;
}
bool operator<=(const real& x1, const double x2)
{
return x1.get_value() + x1.get_error() < x2;
}
int main()
{
return 0;
}
Compiler error:
passing 'const real' as 'this' argument of 'double real::get_alue()' discards qualifiers
However since operator <= is a friend x1.value or x1.error is valid!