(精)jsjg-03.pptVIP

  • 2
  • 0
  • 约1.09万字
  • 约 65页
  • 2017-01-07 发布于北京
  • 举报
第 3 章 友元、重载和引用 本章主要内容 友元(friend):即类的朋友,不同类的成员函数之间、类的成员函数与一般函数进行数据共享的机制; 重载(overloading):同一“符号”在同一作用域的不同场合具有不同的语义(实现算法); 引用(reference):即对象的别名。 #include iostream.h #include iomanip.h class Point { int x, y; public: Point( ) {x=0;y=0;} Point(int px, int py) {x=px;y=py;} }; void show(Point p) { cout“x=”p.xendl; //Error x: cannot access private member declared in class Point couty=p.yendl; // Error y: cannot access private member declared in class Point } void main( ) { Point p1(100,100), p2(20,20); show(p1);

文档评论(0)

1亿VIP精品文档

相关文档