【发布时间】:2016-03-18 21:25:15
【问题描述】:
我有一个名为 shape 的抽象类。
class Shape{
public:
virtual const ColorRGB getColor() const;
virtual double rayIntersectionDistance(Ray r) = 0;
};
现在我从 Shape 派生了以下类。
class Sphere: public Shape { //implementation goes here }class Plane: public Shape { //implementation goes here }
我已经在这两个类中实现了 getColor() 和 rayIntersectionDistance(Ray r) 方法,以及特定于这些类的其他方法。
所以现在,在另一个名为 Scene 的类中,我有一个 render() 方法,它的原型是:
void render(int width, int height, Shape s);
这似乎不起作用,编译器抱怨我说:
错误:不能将参数“s”声明为抽象类型“Shape”
我怎样才能做到这一点?有什么更好的方法来实现这一点?
【问题讨论】: