C ++派生类是抽象错误 [英] C++ Derived class is abstract error
本文介绍了C ++派生类是抽象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个麻烦,在Dialin,派生类是抽象的。我不知道为什么,因为我唯一的虚拟函数,我有相同的参数和相同的返回类型。从我读过的,这是唯一的限制,但显然我错了。
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.
这是我的代码:
标题:
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 ) {
}
推荐答案
问题是有两种不同的转发声明 ModemSimV2
的类别:
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.
在事件
c $ c> process()是:
In Event
, the signature of process()
is:
virtual void process( Event::ModemSimV2 &m ) = 0;
和 Dialin
c $ c> process()实际上是:
and in Dialin
the definition of process()
is actually:
virtual void process( Dialin::ModemSimV2 &m );
因此在 Event
未在 Dialin
中实现。
这篇关于C ++派生类是抽象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文