关于继承问题,
/*写一个艺术类Arts,提供一个print()函数显示艺术品的信息,写两个艺术品子类painting 和music,其中painting信息有作者,年代,尺寸,music再分两个子类,流行音乐和摇滚,前者的信息包括作者,年代,时间长短和演唱者,,后者的信息为作者,年代,时间长短,和演奏人数。写一个全局函数,void show(arts&a){ a.ptint(); }
在main函数里用每种艺术品子类创建一个对象,调用show函数分别显示它们的信息。
*/
#include<iostream>
using namespace std;
class Arts{
public:
Arts(const string & name,int year):mName(name),mYear(year){}
virtual void print(void){}
protected:
string mName;
int mYear;
friend void show(Arts &a);
};
class Painting:public Arts{
Painting(const string & name,int year,int size):Arts(name,year),/*mName(name),mYear(year),*/mSize(size){}
void print(void){
cout<<"作者是:"<<mName<<","<<"演唱于"<<mYear<<"年,"<<"大小为"<<mSize<<"."<<endl;
}
private:
int mSize;
};
class Music:public Arts{
Music(const string & name,int year,int time):Arts(name,year),mTime(time){}
protected:
int mTime;
};
class Pop:public Music{
Pop(const string & name,int year,int time,const string& mname):Music(name,year,time),mmName(mname){}
void print(void){
cout<<"作者是:"<<mName<<","<<"演唱于"<<mYear<<"年,"<<"时间为"<<mTime<<"."<<"演唱者是"<<mmName<<"."<<endl;
}
private:
string mmName;
};
class Poo:public Music{
Poo(const string & name,int year,int time,int num):Music(name,year,time),mNum(num){}
void print(void){
cout<<"作者是:"<<mName<<","<<"演唱于"<<mYear<<"年,"<<"时间为"<<mTime<<"."<<"演唱人数为"<<mNum<<"."<<endl;
}
private:
int mNum;
};
void show(Arts& a){
a.print();
}
int main()
{
Arts a1 = Painting("laoma",1989,20);
show(a1);
return 0;
}
程序哪里有问题呀?????