I have a defined type Coordinates like so:
#include <array>
using Coordinates = std::array<double, 3>;
For which I call the following operator overload functions:
Coordinates operator+(const Coordinates& lhs, const Coordinates& rhs);
Coordinates operator*(const Coordinates& lhs, const Coordinates& rhs);
both overloads work, so that if I have 2 Coordinates variables :
C1 = { 1., 2., 3.} and
C2 = { 1., 2., 3. }
C1+C2 returns { 2., 4., 6.}
C1*C2 returns { 1., 4., 9.}
Now I want to define a *+ operator such that:
C1*+C2 returns 1. + 4. + 9. or 14.
I tried the following implementation:
Coordinates operator*+(const Coordinates& lhs, const Coordinates& rhs)
{
return lhs[0] * rhs[0] + lhs[1] * rhs[1] + lhs[2] * rhs[2];
}
however, *+ is not a pre-defined operator. Then I tried this format:
Coordinates operator "" *+(const Coordinates& lhs, const Coordinates& rhs)
{
return lhs[0] * rhs[0] + lhs[1] * rhs[1] + lhs[2] * rhs[2];
}
but I get this : invalid literal operator name. Understandable how about this:
double operator "" _d_(const Coordinates& lhs, const Coordinates& rhs)
{
return lhs[0] * rhs[0] + lhs[1] * rhs[1] + lhs[2] * rhs[2];
}
_d_ stands for dot as in dot product, but now I get this error too many parameters for this literal. Is it possible to define an operator for the dot product or do I have to write a dot() function?