I'd like to perform some calculations on a vector of long double. The calculations should only be performed once. To solve the problem, I've created a private class LongDouble that sets a flag when a long double value is set. Each result of a calculation, for example min, is then defined as a LongDouble. I get compile errors, as shown below.
Line 17/18: Add const to the functions.
Line 21: mutable is not necessary. Better remove it.
Line 29: Either you remove const for this function or you declare sum as mutable.
thanks, that works when setting min & max, but when attempting to perform a calculation on the result of min & max, say for example "range", I get an implicit type conversion.
I have however defined range as type LongDouble as well, so I'm not sure why the error? Could you help explain?
error is:
test_long_double.cpp:50:50: error: could not convert ‘(tester::maximum().tester::LongDouble::operatorlongdouble() - tester::minimum().tester::LongDouble::operatorlongdouble())’ from ‘longdouble’ to ‘tester::LongDouble’
The operator =(...) can only be used for existing objects. On line 50 however you try to create a new temporary LongDouble object. This requires that the constructor accepts longdouble.
So either you add a constructor that accepts longdouble or you overload the operator-(...) which returns LongDouble. Or you create a local variabe in range() where you assign the result of the operation.