第三章 赖泥和对象.pptVIP

  • 1
  • 0
  • 约1.56万字
  • 约 64页
  • 2017-10-18 发布于浙江
  • 举报
第三章 赖泥和对象

* void main(void) { Stu stu[3]; //定义类的数组 Stu *pstu; //定义类的指针 pstu=stu; //为指针赋值 int i; stu[0].SetStudent (“A”,90,90);//通过数组元素的引用赋值 stu[1].SetStudent (B,80,80); stu[2].SetStudent (C,70,70); for(i=0;i3;i++) { pstu-Show ();//指针变量指向数组元素 pstu++; //指针变量加一,指向下一元素 } } stu pstu pstu * 返回引用类型的成员函数(可以返回私有数据成员的引用) class A{ float x,y; public: float Getx(void ) { return x; } //返回x的引用 void Set(float a,float b) { x=a; y=b; } void Print(void) { coutx\tyendl; } }; void main(void) { A a1,a2; a1.Set (3,5); couta1: ; a1.Print (); a1.Getx()=30; //将a1对象中的x成员赋值 coutchanged

文档评论(0)

1亿VIP精品文档

相关文档