I am getting a very strange error on a very simple code that I couldn't fix.
I have defined the following function object:
template<const size_t n> class L2Norm {
public:
double operator()(const Point<n>& p) {
/* computes the L2-norm of the point P ... */
}
double operator()(const Point<n>& p,
const Point<n>& q) {
return L2Norm<n>(p-q);
}
};
Here the class Point<n>
is well defined before to store the n
coordinates of a point in n
-dimensional space (with required operators, ...).
I expect to get the l2-norm of a point p
(created as Point<5> p
for example) using L2Norm<5>(p)
. But this gives me the following error:
no matching function for call to ‘L2Norm<5ul>::L2Norm(Point<5ul>&)’
note: candidates are: L2Norm<n>::L2Norm() [with long unsigned int n = 5ul]
note: candidate expects 0 arguments, 1 provided
note: L2Norm<5ul>::L2Norm(const L2Norm<5ul>&)
note: no known conversion for argument 1 from ‘Point<5ul>’ to ‘const L2Norm<5ul>&’
I'm pretty sure that I am doing a very stupid mistake but I cannot find out where!
P.S. As a side question, it would be much nicer if I could say L2Norm(p)
only and the compiler detects the template parameter from p
but to the best of my knowledge this is not possible. Am I right?