0

I want to make in-class friend function definition to keep my API consistent in single place. I can't understand how to make that piece of code work and why it doesn't work now
All I want is to create a free function specialization inside a class and keep access to private members

template<class T, class R = T>
R lerp(T a, T b, double t) {
    return (1.0 - t) * a + b * t;
}

class Vec {
    double x, y;
public:
    Vec(double x, double y) : x(x), y(y) {}

    template<>
    friend Vec lerp<const Vec&, Vec>(const Vec& a, const Vec& b, double t) {
        return Vec(lerp(a.x, b.x, t), lerp(a.y, b.y, t), t);
    }
};

I searched for similar questions and had found it quite hard to understand

IC_
  • 1,624
  • 1
  • 23
  • 57

0 Answers0