【发布时间】:2020-12-16 05:58:25
【问题描述】:
我试图在它的一个函数中实例化一个模板类,但由于某种原因我无法这样做。它告诉我错误并指向行首,这没有意义。
template<typename O>
class ray{
...
color<O> ray_color(const ray<O>& ray, const hittable_list<O>& world, O t_Min, O t_Max, int depth){
hit_record<O> rec;
if (world.hit(ray, t_Min, t_Max, rec)){
Vec3<O> target = rec.p + rec.normal + Vec3<O>::random_in_unit_sphere();
ray<O> new_ray(rec.p, (target - rec.p)); //line where it fails
ray.direction() = target - rec.p;
return ray_color(new_ray, world, t_Min, t_Max, depth-1) * 0.5;
}
它给了我这个错误:
Ray.h: In member function ‘color ray::ray_color(const ray&, const hittable_list&, O, O, int)’:
Ray.h:61:16: error: expected primary-expression before ‘>’ token
ray<O> new_ray(rec.p, (target - rec.p));
^
这也会导致 new_array 未被声明并给出后续错误。
我在其他地方使用相同的语法创建了射线对象,但只有这个对象给我一个错误。什么给了?
注意:我知道类函数应该在单独的 cpp 文件中实现。我计划在我的程序运行后进行所有类似的清理工作。
【问题讨论】:
标签: c++ class templates instance raytracing