C ++派生类是抽象错误

时间:2012-04-10 16:59:07

标签: c++ inheritance virtual abstract-class

我遇到了Dialin的问题,派生类是抽象的。我不确定为什么因为我所拥有的唯一虚函数具有相同的参数和相同的返回类型。从我所读到的,这是唯一的限制,但显然我错了。

这是我的代码:

部首:

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;
 };

来源:

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 ) {        
}

1 个答案:

答案 0 :(得分:9)

问题是名为ModemSimV2的类有两种不同的前向声明:

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

Event中,process()的签名是:

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

并且Dialin process()的定义实际上是:

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

所以Event中声明的纯虚函数未在Dialin中实现。