samedi 3 décembre 2016

unimplemented pure virtual method

I'm trying to implement a pure method from a class Algorithm to a class BasicAlgo like this :

class Algorithm
{
    public:
        virtual void solve() = 0;
};

class BasicAlgo : public Algorithm
{
    public:
         void solve() { };
};

Algorithm a = BasicAlgo();
a.solve();

But I'm getting this error :

variable type 'Algorithm' is an abstract class
    Algorithm a = BasicAlgo();
              ^
unimplemented pure virtual method 'solve' in 'Algorithm'
            virtual void solve() = 0;

After lots of time on Stackoverflow looking for a solution, I still don't really understand why there is an error. To me a.solve() is BasicAlgo::solve witch is well implemented.

Aucun commentaire:

Enregistrer un commentaire