朋友模板专业化

时间:2020-05-13 06:28:30

标签: c++

我想在类中定义朋友函数,以使我的API在单个位置保持一致。我不明白如何使这段代码正常工作以及为什么现在不起作用
我想要做的就是在一个类中创建一个免费的函数专业化并保持对私有成员的访问

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);
    }
};

我搜索了similar个问题,发现很难理解

0 个答案:

没有答案
相关问题