Bây giờ bạn biết thêm một chút về cách sử dụng các thành viên bảo vệ trong một lớp học thực tế, tôi có thể xem lại các đối số để sử dụng thành viên được bảo vệ. Làm thành viên điểm trung bình bảo vệ ngăn cản các ứng dụng từ thiết lập các điểm trung bình để một số giá trị tùy ý. | 248 Part III Introduction to Classes The destructor for Person now indicates that the string pointers in pl and p2 don t point to common block of data. Note again that the destructor outputs the most helpful destructing. message for debug purposes instead of actually doing anything. It s a Long Wag to Temporaries C generates a copy of an object to pass to a function by value. This is described in the earlier sections of this chapter. This is the most obvious but not the only example. C creates a copy of an object under other conditions as well. Consider a function that returns an object by value. In this case C must create a copy using the copy constructor. This situation is demonstrated in the following code snippet Student fn returns object by value int main int argcs char pArgs Student s s fn call to fn creates temporary how long does the temporary returned by fn last return 0 The function fn returns an object by value. Eventually the returned object is copied to s but where does it reside until then C creates a temporary object into which it stuffs the returned object. Okay you say. C creates the temporary but how does it know when to destruct it Good question. In this example it doesn t make much difference because you ll be through with the temporary when the copy constructor copies it into s. But what if s is defined as a reference int main int argcs char pArgs Student refS fn .now what . return 0 It makes a big difference how long temporaries live because refS exists for the entire function. Temporaries created by the compiler are valid throughout the extended expression in which they were created and no further. In the following function I mark the point at which the temporary is no longer valid Chapter 18 Copying the Copy Copy Copy Constructor 249 Student fn1 int fn2 Student int main int argcs char pArgs int x create a Student object by calling fn1 . Pass that object to the function fn2 . fn2 .