c++ - Class isn't abstract but I get Error C2259: cannot instantiate abstract class -


i'm trying implement strategy pattern in c++, following error:

error 1 error c2259: 'linearrootsolver' : cannot instantiate abstract class

here's code (the line error is, marked comment). class uses strategy pattern (context):

bool isosurface::intersect(hitinfo& result, const ray& ray, float tmin, float tmax) {     inumericalrootsolver *rootsolver = new linearrootsolver(); // error here     [...] } 

and here's strategy pattern classes:

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) {         [...]     } }; 

i can't see why error trying instantiate abstract class in intersect method @ top?

 void findroot(vector3* p, float a, float b, ray& ray) = 0;                     //^^ 

and

void findroot(vector3& p, float a, float b, ray& ray)                //^^ 

parameter type mismatch, findroot inherited form based class still pure virtual function (not overriding), make linearrootsolver class abstract class. when do:

  inumericalrootsolver *rootsolver = new linearrootsolver(); 

it tries create object of abstract class, got compiler error.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -