dajee
dajee

Reputation: 964

C++ Derived class is abstract error

I am having a trouble where Dialin, the derived class is abstract. I'm not sure why since the only virtual function I have has the same parameters and same return types. From what I've read, that's the only restriction, but apparently I'm wrong.

Here's my code:

Header:

class Event{
    class ModemSimV2;

public:
    Event( );
    Event( const Event &e );
    ~Event( );

    virtual void process( ModemSimV2 &m ) = 0;

protected:
    int who;        // the number of the user
    int time;       // when the event will occur
    int what;       // DIAL_IN or HANGUP
};


 class Dialin : public Event{
     class ModemSimV2;
 public:
     Dialin( int name = 0, int tm = 0 );
     Dialin( const Dialin &d );
     ~Dialin( );

     virtual void process( ModemSimV2 &m );

 private:
     int who;
     int time;
     int what;
 };

Source:

Event::Event(){
}

Event::Event( const Event &e ) {
    *this = e;
}

Event::~Event( ) {
}

Dialin::Dialin (int name, int tm )
: time( tm ), who( name ) { 
    return;
}

Dialin::Dialin ( const Dialin &d ) {
    *this = d;
}

Dialin::~Dialin( ) {
}

void Dialin::process( ModemSimV2 &m ) {        
}

Upvotes: 1

Views: 1137

Answers (1)

hmjd
hmjd

Reputation: 121961

The problem is that there are two different forward declarations of a class named ModemSimV2:

Event::ModemSimV2          // These are different classes
Dialin::ModemSimV2         // with the same unqualified name.

In Event, the signature of process() is:

virtual void process( Event::ModemSimV2 &m ) = 0;

and in Dialin the definition of process() is actually:

virtual void process( Dialin::ModemSimV2 &m );

so the pure virtual function declared in Event is not being implemented in Dialin.

Upvotes: 9

Related Questions