首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

急改错。解决办法

2012-04-19 
急,改错。。。#includeiostream#includecstringusing namespace stdclass circle{public:circle(double

急,改错。。。
#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;//函数写错了
}

热点排行