Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type a must implement the inherited pure virtual method b

Tags:

c++

I want simulated interface sterotype in C++ using abstract class. But in Eclipse IDE I get "Multiple markers at this line - The type 'Handler' must implement the inherited pure virtual method 'Handler::setNext'"

My question is Why this?.

Handler.h

class Handler {
 public:

    virtual void setNext(Handler &next)  = 0;
    Handler();
    virtual ~Handler();
    virtual void process()  = 0;
 public:

    Handler *nextInChain;

};

Handler.cpp

#include "Handler.h"
Handler::Handler(){
}
Handler::~Handler(){
}

Oracle.h

#include "Handler.h"
class Oracle : virtual public Handler {
 public:
    Oracle();
    virtual ~Oracle();
    virtual void process();
    virtual void setNext(Handler &next);
 private:

};

Oracle.cpp

#include "Oracle.h"

Oracle::Oracle(){
Handler AQUI;//AQUI I get Multiple markers at this line
             //- The type 'Handler' must implement the inherited pure virtual method 
 //'Handler::setNext'
}

Oracle::~Oracle(){
}

void Oracle::process(){
}

void Oracle::setNext(Handler &next){
}
like image 872
Juan Avatar asked Feb 12 '13 20:02

Juan


1 Answers

This is incorrect:

Handler AQUI;

You cannot instantiate an abstract class.

What you want to do is define a pointer to Handler and assign it the address of a valid object from a child class, like Oracle.

like image 122
imreal Avatar answered Nov 15 '22 06:11

imreal