静态成员去与友元.pptVIP

  • 0
  • 0
  • 约7.41千字
  • 约 31页
  • 2019-01-18 发布于福建
  • 举报
静态成员去与友元

第15章 静态成员与友元 类是类型而不是对象,每个类的对象都是该类数据成员的拷贝。 然而,往往需要让类的所有对象在类的范围内共享某个数据。 声明为static的类成员便能在类范围中共享,称之为静态成员。 友元函数完全是普通的C++函数,不同的是,它可以访问类的保护成员或私有成员,方便编程,提高了效率,但却破坏了类的封装。 15.1 静态成员的需要性 15.2 静态成员的使用 15.3 静态数据成员 15.4 静态成员函数 15.5 需要友元的原因 15.6 友元的使用 #include iostream.h #include string.h int nextStudentID=0; Class StudentID {public:StudentID( ) {value=++nextStudentID; cout“Assigning student id ”valueendl;} ~StudentID( ) {- -nextStudentID; cout“Destructing id”valueendl;} protected:int value;}; Class Student {public:Student(char *pName=“noNa

文档评论(0)

1亿VIP精品文档

相关文档