基类中的纯虚类成员函数需要在派生类中实现其定义,
#include <iostream>
using namespace std;
class myBase
{
private:
/* data */
int m_id;
int m_width;
int m_height;
public:
myBase(/* args */);
~myBase();
int firstFunction();
virtual int onConnect() = 0;
virtual int onDataIn() = 0;
};
myBase::myBase(/* args */)
{
printf("construct myBase obj\n");
}
myBase::~myBase()
{
printf("destory myBase obj\n");
}
class myPeople: public myBase
{
private:
/* data */
public:
myPeople(/* args */);
~myPeople();
virtual int onConnect();
virtual int onDataIn();
};
myPeople::myPeople(/* args */)
{
printf("construct myPeople obj\n");
}
myPeople::~myPeople()
{
printf("destory myPeople obj\n");
}
int myPeople::onConnect()
{
printf("onConnect comming\n");
}
int myPeople::onDataIn()
{
printf("onDataIn comming\n");
}
int main()
{
myPeople *pobj = new myPeople;
cout << "pobj" << pobj << endl;
delete pobj;
printf("[%s|%d] main exit\n", __FUNCTION__, __LINE__);
return 0;
}
|