I have a class with two friend operator overloadings inside:
template<typename T>
class A {
T i;
template <typename L, typename R>
friend auto operator+(const A<L> &l, const A<R> &r) -> A<decltype(l.i + r.i)>;
template <typename L>
friend auto operator+(const A<L> &l, const T &r) -> A<decltype(l.i + r)>;
}
I wanted to know how can I create a definition for these functions in a .cpp
file (since the declarations are in a header file).
For now I did this but it throws an error:
template <typename L, typename R>
auto operator+(const A<L> &l, const A<R> &r) -> A<decltype(l.i + r.i)>
{
return Vector3Generic<decltype(l.i + r.i)>(l.x + r.x, l.y + r.y, l.z + r.z);
}
The error:
Undefined symbols for architecture x86_64:
"A<decltype((fp.x) + (fp0.x))> operator+<float, float>(A<float> const&, A<float> const&)"
And I absolutely don't know how to define the second operator overload using the parent's T
.