新微赢技术网

标题: [转载][求助] [打印本页]

作者: ●.涛涛"★    时间: 2009-11-4 01:28
标题: [转载][求助]
#include "stdafx.h"
#include "iostream.h"
class Point
{
public:
Point(double i,double j){x=i;y=j;}
double Area() const{return 0.0;}
private:
double x,y;
};
class Rectangle:public Point
{
public:
Rectangle(double i,double j,double k,double l);
double Area()const{return w*h;}
private:
double w,h;
}
Rectangle::Rectangle(double i,double j,double k,double l):Point(i,j)
{
w=k;
h=l;
}
void fun(Point &s)
{
cout<<s.Area()<<endl;
}
void main()
{
Rectangle rec(3.0, 5.2, 15.0, 25.0);
fun(rec);
}
调试的错误是
C:\Program Files\Microsoft Visual Studio\MyProjects\lanshulin31\lanshulin31.cpp(22) : error C2533: 'Rectangle::Rectangle' : constructors not allowed a return type
C:\Program Files\Microsoft Visual Studio\MyProjects\lanshulin31\lanshulin31.cpp(33) : error C2264: 'Rectangle::Rectangle' : error in function definition or declaration; function not called
这是什么错误啊,高手指教
作者: 金马    时间: 2009-11-4 01:28
  1. #include <iostream>
  2. using namespace std;

  3. class Point
  4. {
  5. public:
  6. Point(double i = 0, double j = 0)
  7. {
  8. x=i;
  9. y=j;
  10. }
  11. private:
  12. double x, y;
  13. };

  14. class Rectangle
  15. {
  16. public:
  17. Rectangle(double i, double j, double k, double l)
  18. {
  19. point = Point(i, j);
  20. w=k;
  21. h=l;
  22. }
  23. double area() const
  24. {
  25. return w*h;
  26. }
  27. private:
  28. Point point;
  29. double w,h;
  30. };


  31. int main()
  32. {
  33. Rectangle rect(3.0, 5.2, 15.0, 25.0);
  34. cout<<rect.area()<<endl;

  35. return 0;
  36. }

复制代码

作者: 小华﹖    时间: 2009-11-4 01:28
2楼
格式看起来好舒服
代码写的好

我向你学习




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2