新微赢技术网
标题:
[转载][求助]
[打印本页]
作者:
●.涛涛"★
时间:
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
#include <iostream>
using namespace std;
class Point
{
public:
Point(double i = 0, double j = 0)
{
x=i;
y=j;
}
private:
double x, y;
};
class Rectangle
{
public:
Rectangle(double i, double j, double k, double l)
{
point = Point(i, j);
w=k;
h=l;
}
double area() const
{
return w*h;
}
private:
Point point;
double w,h;
};
int main()
{
Rectangle rect(3.0, 5.2, 15.0, 25.0);
cout<<rect.area()<<endl;
return 0;
}
复制代码
作者:
小华﹖
时间:
2009-11-4 01:28
2楼
格式看起来好舒服
代码写的好
我向你学习
欢迎光临 新微赢技术网 (http://bbs.weiying.cn/)
Powered by Discuz! X3.2