我已经编写了以下代码。
#include <iostream>
using namespace std;
class CI
{
public:
virtual void display() =0;
};
class Inter: public CI
{
public:
int parseData (int);
};
Inter::parseData (int data)
{
cout <<"Parsing the data "<<data;
return data*100;
}
class Last: public Inter
{
public:
void display();
};
void Last::display()
{
cout <<" Last:: Displaying From Last "<<endl;
}
class USB: public Inter
{
public:
void display();
};
void USB::display()
{
cout <<" USB:: Displaying From Last "<<endl;
}
int main ( int argc, char ** argv)
{
int temp;
CI *obj = new Last;
obj->display();
temp = obj->parseData (100);
cout <<"Parsed DAta .. "<<temp<<endl;
delete obj;
obj = new USB;
obj->display();
temp = obj->parseData (200);
}
我的问题是:
为什么我不能调用 obj->parseData 函数?据我了解,因此类“Last”和“USB”派生自“Inter”类,它应该是可调用的吗?
请告诉我我的理解错在哪里?