C++第四章 类与对象.pptVIP

  • 2
  • 0
  • 约2.15万字
  • 约 38页
  • 2016-09-19 发布于江西
  • 举报
C++第四章 类与对象.ppt

* // 跟踪拷贝构造函数 #include iostream.h class Ratio { public: Ratio(int n=0, int d=1) : num(n), den(d) { cout 构造函数...\n; } Ratio(const Ratio r) : num(r.num), den(r.den) { cout 拷贝构造函数...\n; } private: int num, den; }; Ratio f(Ratio r) { Ratio s = r;//调用拷贝构造函数, r to s return s; } void main( ) { Ratio x(22,7); cout ****** 1 ******\n; Ratio y(x); cout ****** 2 ******\n; Ratio z; cout ****** 3 ******\n; z=f(y); } * * 如果希望程序在对象被删除前的时刻自动完成某些事情,可以写入析构函数中。 * * // Tracing calls to the copy constructor #include iostream.h class R

文档评论(0)

1亿VIP精品文档

相关文档