C++抽象类的问题,编译时没错误,连接却出现错误,晕啊,找了很久都找不出那里错,大家帮我改改吧,谢谢了!
#include<iostream.h>
class Gz
{
public:
virtual double getgz()=0;
};
class A:public Gz
{
protected:
int week;
int xinshui;
public:
A(){};
A(int week,int xinshui)
{
this->week=week;
this->xinshui=xinshui;
}
double getgz()
{
return week*xinshui;
}
};
class B:public Gz
{
protected:
int hour;
int axinshui;
int jiaban;
public:
B(){};
B(int hour,int axinshui,int jiaban)
{
this->hour=hour;
this->axinshui=axinshui;
this->jiaban=jiaban;
}
double getgz()
{
return hour*axinshui+jiaban;
}
};
class C:public Gz
{
protected:
int xsk;
public:
C(){};
C(int xsk)
{
this->xsk=xsk;
}
double getgz()
{
return xsk*0.05;
}
};
void main(){
Gz* Gz[3]={
new A(2,500),new B(50,8,100),new C(5000)
};
for(int i=0;i<3;i++){
cout<<(Gz[i])->getgz()<<" ";
}
}