TAILIEUCHUNG - Absolute C++ (4th Edition) part 45

Absolute C++ (4th Edition) part 45. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | 446 Pointers and Dynamic Arrays destructor name object from a class with a destructor then when the function call ends the destructor will be called automatically. If the destructor is defined correctly the destructor will call delete to eliminate all the dynamically allocated variables created by the object. This may be done with a single call to delete or it may require several calls to delete. You may also want your destructor to perform some other clean-up details as well but returning memory to the freestore manager for reuse is the main job of the destructor. The member function PFArrayD is the destructor for the class PFArrayD shown in Display . Like a constructor a destructor always has the same name as the class of which it is a member but the destructor has the tilde symbol at the beginning of its name so you can tell that it is a destructor and not a constructor . Like a constructor a destructor has no type for the value returned not even the type void. A destructor has no parameters. Thus a class can have only one destructor you cannot overload the destructor for a class. Otherwise a destructor is defined just like any other member function. Notice the definition of the destructor PFArrayD given in Display . PFAr-rayD calls delete to eliminate the dynamically allocated array pointed to by the member pointer variable a. Look again at the function testPFArrayD in the sample program shown in Display . The local variable temp contains a dynamic array pointed to by the member variable . If this class did not have a destructor then after the call to testPFArrayD ended this dynamic array would still be occupying memory even though the dynamic array is useless to the program. Moreover every iteration of the do-while loop would produce another useless dynamic array to clutter up memory. If the loop is iterated enough times the function calls could consume all the memory in the freestore manager and your program would then end abnormally. .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.