我想实现C++中的策略模式,但我得到了以下错误:类不是抽象的,但我得到错误C2259:不能实例化抽象类
错误1个错误C2259:“LinearRootSolver”:不能实例化抽象类
这里是我的代码(错误所在的行标有注释)。使用策略模式(上下文) 类:
bool Isosurface::intersect(HitInfo& result, const Ray& ray, float tMin, float tMax) {
INumericalRootSolver *rootSolver = new LinearRootSolver(); // error here
[...]
}
这是我的战略格局类:
class INumericalRootSolver {
public:
virtual void findRoot(Vector3* P, float a, float b, Ray& ray) = 0;
};
class LinearRootSolver : public INumericalRootSolver {
public:
void findRoot(Vector3& P, float a, float b, Ray& ray) {
[...]
}
};
我不明白为什么我得到一个错误的尝试实例在一个抽象类在顶部相交的方法?
我的天啊。这是一个邪恶的错字,感谢您为我找到它。嘿。 –
@MarcIlsøPoulsen欢迎您 – taocp