C++教程1-10章5-类与对象.pptVIP

  • 1
  • 0
  • 约22.69万字
  • 约 528页
  • 2018-04-23 发布于广东
  • 举报
class A { public : A ( int ) ; A ( const A , int =1 ) ; … } ; … A a ( 1 ) ; A b ( a , 0 ) ; A c = b ; 5.3.4 复制构造函数 5.3.4 复制构造函数 class A { public : A ( int ) ; A ( const A , int =1 ) ; … } ; … A a ( 1 ) ; A b ( a , 0 ) ; A c = b ; 5.3.4 复制构造函数 // 构造函数 5.3.4 复制构造函数 class A { public : A ( int ) ; A ( const A , int =1 ) ; … } ; … A a ( 1 ) ; A b ( a , 0 ) ; A c = b ; 5.3.4 复制构造函数 // 复制构造函数 5.3.4 复制构造函数 class A { public : A ( int ) ; A ( const A , int =1 ) ; … } ; … A a ( 1 ) ; A b ( a , 0 ) ; A c = b ; 5.3.4 复制构造函数 // 复制构造函数 // 创建对象 a,调用 A (int) 5.3.4 复制构造函数 class A { public : A ( int ) ; A ( const A , int =1 ) ; … } ; … A a ( 1 ) ; A b ( a , 0 ) ; A c = b ; 5.3.4 复制构造函数 // 复制构造函数 //创建对象 b,调用 A (const A , int =1) 5.3.4 复制构造函数 #includeiostream.h // 例5-6 class Date { public: Date() ; ~Date() ; void SetDate( int y, int m, int d ) ; int IsLeapYear() ; void PrintDate() ; private: int year, month, day ; } ; Date:: Date() { cout Date object initialized.\n ; } // 无参构造函数 Date:: ~Date() { cout Date object destroyed.\n ; } // 析构函数 void Date:: SetDate( int y, int m, int d ) { year = y ; month = m ; day = d ; } int Date::IsLeapYear() { return ( year%4==0 year%100!=0 ) || ( year%400==0 ) ; } void Date::PrintDate() { cout year / month / day endl ; } void main() { Date d ; d.SetDate(2001,10,1) ; d.PrintDate() ; } ~Date() ; Date:: ~Date() { cout Date object destroyed.\n ; } // 析构函数 作用域结束时 调用析构函数 5.3.1 简单构造函数和析构函数 #includeiostream.h // 例5-6 class Date { public: Date() ; ~Date() ; void SetDate( int y, int m, int d ) ; int IsLeapYear() ; void PrintDate() ; private: int year, month, day ; } ; Date:: Date() { cout Date object initialized.\n ; } // 无参构造函数 Date:: ~Date() { cout Date object destroyed.\n ; } // 析构函数 void Date:: S

文档评论(0)

1亿VIP精品文档

相关文档