找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1594|回复: 2

[转载][求助]

[复制链接]
发表于 2009-11-4 01:28:31 | 显示全部楼层 |阅读模式 IP:江苏扬州
#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:35 | 显示全部楼层 IP:江苏扬州
  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:36 | 显示全部楼层 IP:江苏扬州
2楼
格式看起来好舒服
代码写的好

我向你学习
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 03:33 , Processed in 0.204203 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表