急,改错。。。
#include<iostream>
#include<cstring>
using namespace std;
class circle
{
public:
circle(double r)
{
radius=r;
}
double getarea()
{
return radius*radius*3.14;
}
~circle();
private:
double radius;
};
class table
{
public:
table(double h)
{
height=h;
}
double getheiget()
{
return height;
}
~table();
private:
double height;
};
class roundtable:public circle,public table
{
char *color;
public:
roundtable(char a,double b,double c):table(b),circle(c)
{
color=new char[strlen(a)+1];
}
char getcolor()
{
return *color;
}
~roundtable()
{
delete[] color;
}
};
void main()
{
circle c(2);
table t(2.3);
roundtable r(blue,2.3,2);
cout<<c.getarea()<<" "<<t.getheight()<<" "<<r.getcolor()<<endl;
}
[解决办法]
roundtable(char a,double b,double c):table(b),circle(c)
{
color=new char[strlen(a)+1];
strcpy(color, a); // 这句要加吧。。
}
[解决办法]
#include<iostream>
#include<cstring>
using namespace std;
class circle
{
public:
circle(double r)
{
radius=r;
}
double getarea()
{
return radius*radius*3.14;
}
~circle(){}
private:
double radius;
};
class table
{
public:
table(double h)
{
height=h;
}
double getheiget()
{
return height;
}
~table(){}
private:
double height;
};
class roundtable:public circle,public table
{
char *color;
public:
roundtable(double b,double c):table(b),circle(c)
{
color=new char[5];
}
char getcolor()
{
return *color;
}
~roundtable()
{
delete[] color;
}
};
void main()
{
circle c(2);
table t(2.3);
roundtable r(2.3,2);
cout<<c.getarea()<<" "<<t.getheiget()<<" "<<r.getcolor()<<endl;//函数写错了
}