小马甲又来啦!小问题请大家帮忙~~~~~~~~~~~~~~
如果基类里有纯虚函数,就不能声明该基类的对象
但是如果基类中也有其他函数,那如果要调用该函数怎么办?
例如:
这样是可以输出,但是有错误:局部变量ptr尚未初始化!
咋解决?
但是如果基类中也有其他函数,那如果要调用该函数怎么办?
例如:
#include<iostream.h>
class island
{
public:
void headline(void)
{
cout<<"!!welcome to Island!! \n";
}
virtual void type(void)=0;
};
class type_1:class island
{
public:
void type(void)
{
cout<<"type_1 \n";
}
};
class type_2:class island
{
public:
void type(void)
{
cout<<"type_2 \n";
}
};
main(void)
{
island *ptr;
type_1 t_1;
type_2 t_2;
ptr->headline();
ptr=&type_1;
ptr->type();
ptr=&type_2;
ptr->type();
return(0);
}
这样是可以输出,但是有错误:局部变量ptr尚未初始化!
咋解决?
...全文



