On Thursday, 2 July 2015 at 17:33:29 UTC, Laeeth Isharc wrote:
Any thoughts on what could be leading to the following:
./../../marketdata/source/pricebar.d(397): Error: incompatible
types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and
'FixedDecimal!(int, 8)'
../../../marketdata/source/pricebar.d(399): Error: incompatible
types for ((bar.high) + (bar.low)): 'FixedDecimal!(int, 8)' and
'FixedDecimal!(int, 8)'
../../../marketdata/source/pricebar.d(547): Error: incompatible
types for ((trueHigh(bars)) - (trueLow(bars))):
'FixedDecimal!(int, 8)' and 'FixedDecimal!(int, 8)'
FixedDecimal is a fixed decimal point struct that stores values
as an int or long and takes number of decimal places as the
second compile term argument. It's possible, if not likely I
have made a mistake in implementing operator overloads.
Any thoughts on whether this is the likely cause, and if so
which ones are likely to be the problem?
From the error messages it looks you didn't implement the
operator overloads properly.
You get the same message when FixedDecimal doesn't overload
anything at all:
----
struct FixedDecimal(T, uint n) {}
void main()
{
FixedDecimal!(int, 8) a, b;
auto c = a + b; /* line 5 */
}
----
test.d(5): Error: incompatible types for ((a) + (b)):
'FixedDecimal!(int, 8u)' and 'FixedDecimal!(int, 8u)'
----
You can get a more specific error by instantiating/calling things
explicitly. For example, here I messed up the parameter type:
----
struct FixedDecimal(T, uint n)
{
FixedDecimal opBinary(string op)(FixedDecimal!(T, 0))
{
return FixedDecimal.init;
}
}
void main()
{
FixedDecimal!(int, 8) a, b;
auto c = a + b; /* line 11 */
auto d = a.opBinary!"+"(b); /* line 12 */
}
----
test.d(11): Error: incompatible types for ((a) + (b)):
'FixedDecimal!(int, 8u)' and 'FixedDecimal!(int, 8u)'
test.d(12): Error: function test.FixedDecimal!(int,
8u).FixedDecimal.opBinary!"+".opBinary (FixedDecimal!(int, 0u)
_param_0) is not callable using argument types
(FixedDecimal!(int, 8u))
----
The error for line 11 just says that something went wrong. The
one for line 12 is a little more helpful.