第九章 数据的共享与保护.pptVIP

  • 2
  • 0
  • 约7.53千字
  • 约 38页
  • 2018-04-10 发布于江苏
  • 举报
第九章 数据的共享与保护

* * * * * * * * * * * * * * * 例9-7:常成员函数 //9_7.cpp #include iostream #include iomanip #include CircleCal.h using namespace std; int main() { CircleCal R1(2.5),R2; coutthe aera of R1 is: setw(5)R1.GetR()endl; coutthe aera of R2 is: setw(5)R2.GetR()endl; return 0; } 共享数据的保护 * the aera of R1 is: 2.5 the aera of R2 is: 0 运行结果: 共享数据的保护 * 常对象 常对象就是对象在生存期内不可更改的对象。 常对象首先需要被初始化,然后使用,在使用过程中,常对象只能调用常成员函数,因为一切调用非常成员函数都视为危险的,即便这个非常成员函数并没有修改成员数据。 共享数据的保护 * 例9-8:常对象对函数的调用 #ifndef Circle #define Circle class CircleCal { private: double Radius; //定义半径 static const double PI; public: Circl

文档评论(0)

1亿VIP精品文档

相关文档