TAILIEUCHUNG - A Closer Look at Classes

This module continues the discussion of the class begun in Module 8. It examines a number of class-related topics, including overloading constructors, passing objects to functions, and returning objects. It also describes a special type of constructor, called the copy constructor, which is used when a copy of an object is needed. Next, friend functions are described, followed by structures and unions, and the ‘this’ keyword. The module concludes with a discussion of operator overloading, one of C++’s most exciting features | Module 9 A Closer Look at Classes Table of Contents CRITICAL SKILL Overload CRITICAL SKILL Assign CRITICAL SKILL Pass objects to CRITICAL SKILL Return objects from CRITICAL SKILL Create copy CRITICAL SKILL Use friend CRITICAL SKILL Know the structure and CRITICAL SKILL Understand CRITICAL SKILL Know operator overlaoding CRITICAL SKILL Overlaod operators using member CRITICAL SKILL Overlad operators using nonmember This module continues the discussion of the class begun in Module 8. It examines a number of class-related topics including overloading constructors passing objects to functions and returning objects. It also describes a special type of constructor called the copy constructor which is used when a copy of an object is needed. Next friend functions are described followed by structures and unions and the this keyword. The module concludes with a discussion of operator overloading one of C s most exciting features. 1 C A Beginner s Guide by Herbert Schildt CRITICAL SKILL Overloading Constructors Although they perform a unique service constructors are not much different from other types of functions and they too can be overloaded. To overload a class constructor simply declare the various forms it will take. For example the following program defines three constructors Overload the constructor. include iostream using namespace std class Sample public int x int y Overload the default constructor. Sample x - y 0 ------------------------ Constructor with one parameter. Sample int i x y i -----------Overload the Sample constructor. Constructor with two parameters Sample int i int 1 x i y j int main Sample t invoke default constructor Sample tl 5 use Sample int Sample t2 9 10 use Sample int int cout n cout n cout n return 0 The .

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.