您的位置:首页 > 其它

成员函数、友元函数和一般函数有区别

2014-04-08 16:42 176 查看
/*
* 程序的版权和版本声明部分
* Copyright (c)2014, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: fibnacci.cpp
* 作    者:高古尊
* 完成日期:2014年4月7日
* 版本号: v1.0
*
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
*/
#include <iostream>
#include<cmath>
using namespace std;
class CPoint
{
private:
double x;  // 横坐标
double y;  // 纵坐标
public:
CPoint(double xx=0,double yy=0):x(xx),y(yy){}
void friend cpoin(CPoint &);
double juli();

};
void cpo(CPoint &);
int main()
{
CPoint t1(10,13);
cout<<t1.juli()<<endl;  //成员函数这样调用:对象名.函数名()
cpoin(t1);   //友员函数的调用和一般函数无异(但实现中可以不同)
cpo(t1);   //一般函数的调用
return 0;
}
double CPoint::juli()
{
return sqrt(x*x+y*y);
}
void cpoin(CPoint &t)
{
cout<<sqrt(t.x*t.x+t.y*t.y)<<endl;
}
void cpo(CPoint &t)
{
cout<<t.juli()<<endl;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  class 对象