(资料抽象化)培训教材.pptVIP

  • 0
  • 0
  • 约3.87万字
  • 约 88页
  • 2018-11-08 发布于天津
  • 举报
(资料抽象化)培训教材.ppt

fig07_10.cpp output (1 of 1) Date object constructor for date 7/24/1949 Date object constructor for date 3/12/1988 Employee object constructor: Bob Jones Jones, Bob Hired: 3/12/1988 Birth date: 7/24/1949 Test Date constructor with invalid values: Month 14 invalid. Set to month 1. Day 35 invalid. Set to day 1. Date object constructor for date 1/1/1994 Date object destructor for date 1/1/1994 Employee object destructor: Jones, Bob Date object destructor for date 3/12/1988 Date object destructor for date 7/24/1949 Date object destructor for date 3/12/1988 Date object destructor for date 7/24/1949 Note two additional Date objects constructed; no output since default copy constructor used. Destructor for host object manager runs before destructors for member objects hireDate and birthDate. Destructor for Employee’s member object hireDate. Destructor for Employee‘s member object birthDate. Destructor for Date object hire. Destructor for Date object birth. 7.4 friend Functions and friend Classes friend function (夥伴函數或友誼函數) Defined outside class’s scope Right to access non-public members Declaring friends Function Precede function prototype with keyword friend All member functions of class ClassTwo as friends of class ClassOne Place declaration of form friend class ClassTwo; in ClassOne definition 7.4 friend Functions and friend Classes Properties of friendship Friendship granted, not taken (是授予,不是取得) Class B friend of class A Class A must explicitly declare class B friend Not symmetric (無對稱性) Class B friend of class A Class A not necessarily friend of class B Not transitive (無轉移性) Class A friend of class B Class B friend of class C Class A not necessarily friend of Class C fig07_11.cpp (1 of 3) 1 // Fig. 7.11: fig07_11.cpp 2 // Friends can access private members of a class. 3 #include iostream 4 5 using std::cout; 6 using std::endl; 7 8 // Count class definition 9 class Count { 10 friend void

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档