成员函数、友元函数和一般函数有区别
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; }
相关文章推荐
- 第七周项目3-成员函数、友元函数和一般函数区别
- 项目3-成员函数、友元函数和一般函数有区别
- 成员函数、友元函数和一般函数的区别(两点间距离)
- 飛飛(二十五)成员函数,友元函数,和一般函数的区别1
- 成员函数、友元函数和一般函数的区别-时间
- 第六周项目4.2 成员函数 友元函数和一般函数有区别——点类
- 第6周项目--成员函数、友元函数和一般函数有区别
- 第5周项目4-成员函数、友元函数和一般函数的区别
- C++第7周项目2 - 成员函数、友元函数和一般函数之区别
- 第六周 【项目4-成员函数、友元函数和一般函数有区别】
- 【项目2-成员函数、友元函数和一般函数之区别 点类】
- 第六周项目4:成员函数,友元函数和一般函数有区别
- 项目二(成员函数,友元函数和一般函数之区别)
- 第六周项目4-成员函数、友元函数和一般函数有区别
- 第六周 项目四 成员函数、友元函数和一般函数有区别(2)友函数
- 第六周项目4-成员函数、友元函数和一般函数有区别
- 第6周项目4-成员函数、友元函数和一般函数有区别 (友元函数)
- 第七周项目一 (成员函数,友元函数和一般函数的区别)
- 第七周 项目1-成员函数、友元函数和一般函数有区别(1)友元
- 成员函数、友元函数和一般函数的区别(两点间距离)