标题:類的派生該怎么用??
取消只看楼主
iwar
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-4-16
 问题点数:0 回复次数:1 
類的派生該怎么用??

#include <iostream.h>

#include <math.h> //for sqrt()

class C2D

{

protected:

double x, y; //x and y coordinates

public:

C2D() { x = y = 0.0; } //default constructor

C2D(double i, double j):x(i), y(j) { }

void setX(double newX) { x = newX; }

void setY(double newY) { y = newY; }

double getX() const { return x; }

double getY() const { return y; }

double getDistance(C2D point) const; // get distance of 2D points

};

// calculate the distance of two 2D points

double C2D::getDistance(C2D point) const

{

double dx, dy;

double distance;

dx = x – point.getX();

dy = y – point.getY();

distance = sqrt(dx * dx + dy * dy);

return distance;

}

class C3D:public C2D

{

private:

double z;

public:

C3D():C2D();

C3D(double i, double j, double k);

void setZ(double newZ);

double getZ();

double getDistance(C3D point) const; //get distance for two 3D points

};

該怎麽延伸到三維的啊!!!!
搜索更多相关主题的帖子: 派生 
2007-05-26 14:34
iwar
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-4-16
得分:0 
thx
2007-05-28 18:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-142729-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.779711 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved