#include<iostream>
#include<string>
using namespace std;
class Circle
{
private: double r; //半径
double s;
public:
Circle(double a):r(a){}
double S(){return(s=3.14*r*r);}
};
class Table
{
public:
Table(double a):height(a){}
double show(){return (height);}
private:
double height;
};
class RoundTable: public Table,public Circle
{ private:
string *color; //颜色
public:
RoundTable(double a,double b,string c):Circle(a),Table(b)
{ *color=c;} //错误出在此处
void display();
};
void RoundTable::display()
{cout<<"圆桌高度:"<<show()<<endl<<"圆桌面积:"<<S()<<endl<<"圆桌颜色:"<<*color<<endl;}
int main()
{ RoundTable rt(1.2, 0.8, "黑色");
rt.display();
return 0;
}
我把color声明称string的时候程序可以正常运行,声明成指针的时候显示没错,可是一运行就出现程序停止,怎么回事啊
#include<string>
using namespace std;
class Circle
{
private: double r; //半径
double s;
public:
Circle(double a):r(a){}
double S(){return(s=3.14*r*r);}
};
class Table
{
public:
Table(double a):height(a){}
double show(){return (height);}
private:
double height;
};
class RoundTable: public Table,public Circle
{ private:
string *color; //颜色
public:
RoundTable(double a,double b,string c):Circle(a),Table(b)
{ *color=c;} //错误出在此处
void display();
};
void RoundTable::display()
{cout<<"圆桌高度:"<<show()<<endl<<"圆桌面积:"<<S()<<endl<<"圆桌颜色:"<<*color<<endl;}
int main()
{ RoundTable rt(1.2, 0.8, "黑色");
rt.display();
return 0;
}
我把color声明称string的时候程序可以正常运行,声明成指针的时候显示没错,可是一运行就出现程序停止,怎么回事啊