【发布时间】:2015-03-10 09:30:10
【问题描述】:
我正在尝试实现软件渲染器,它在顶点着色之后发生插值
以下是它的声明
template <class T>
class Interpolatable
{
// The function calculates an interpolated value
// along the fraction t between 0.0 and 1.0.
// When t = 1.0, endValue is returned.
virtual T interpolate(const T &endValue, float t)=0;
};
struct Vertex: public Interpolatable<?????????>
{
float x, y, z;
Vertex()=default;
Vertex(float, float, float);
virtual Vertex &interpolate(const Vertex &endValue, float t) const;
};
是否可以让 Vertex 的 interpolate 方法返回 Vertex 的实例? 编译器总是给我错误
【问题讨论】:
-
struct Vertex: public Interpolatable
你想使用 CRTP 吗? -
struct Vertex: interpolatable<Vertex>应该可以工作。注意你需要返回Vertex,不是Vertex& -
您似乎错过了
T const& beginValue以返回t==0案件。
标签: c++ templates inheritance interface