第六章面向对象程序设计基础[001].pptVIP

  • 2
  • 0
  • 约1.22万字
  • 约 56页
  • 2018-08-30 发布于湖北
  • 举报
第六章 面向对象程序设计基础 6.1 面向对象程序设计概述 6.2 结构 6.3 类和对象 6.4 继承和派生 6.5多态性 6.6 程序举例 6.3.6 友元函数 [例6.9]友元函数示例程序 #include iostream.h #include math.h class Cpoint {private: int X,Y; public: Cpoint(int x, int y) { X=x; Y=y; } void print(); friend double dist(Cpoint a,Cpoint b); }; void Cpoint::print() { coutXY ; } double dist(Cpoint a,Cpoint b) { int dx=a.X-b.X; int dy=a.Y-b.Y; return sqrt(dx*dx+dy*dy); } void main() {Cpoint p1(3,4),p2(6,8); p1.print(); p2.print(); double d=dist(p1,p2); /*友元不是成员函数不需对象表示,直接调用*/ cou

文档评论(0)

1亿VIP精品文档

相关文档