Classes and Objects

Up to this point, you have been writing programs that did not use any of C++’s object-oriented capabilities. Thus, the programs in the preceding modules reflected structured programming, not object-oriented programming. To write object-oriented programs, you will need to use classes. The class is C++’s basic unit of encapsulation. Classes are used to create objects. Classes and objects are so fundamental to C++ that much of the remainder of this book is devoted to them in one way or another. . | Module8 Classes and Objects Table of Contents CRITICAL SKILL The General Form of a CRITICAL SKILL Defining a Class and Creating CRITICAL SKILL Adding Member Functions to a Project 8-1 Creating a Help CRITICAL SKILL Constructors and CRITICAL SKILL Parameterized CRITICAL SKILL Inline CRITICAL SKILL Arrays of CRITICAL SKILL Initializing Object CRITICAL SKILL Pointers to Up to this point you have been writing programs that did not use any of C s object-oriented capabilities. Thus the programs in the preceding modules reflected structured programming not object-oriented programming. To write object-oriented programs you will need to use classes. The class is C s basic unit of encapsulation. Classes are used to create objects. Classes and objects are so fundamental to C that much of the remainder of this book is devoted to them in one way or another. Class Fundamentals Let s begin by reviewing the terms class and object. A class is a template that defines the form of an object. A class specifies both code and data. C uses a class specification to construct objects. Objects are instances of a class. Thus a class is essentially a set of plans that specify how to build an object. It is important to be clear on one issue a class is a logical abstraction. It is not until an object of that class has been created that a physical representation of that class exists in memory. When you define a class you declare the data that it contains and the code that operates on that data. While very simple classes might contain only code or only data most real-world classes contain both. 1 C A Beginner s Guide by Herbert Schildt Data is contained in instance variables defined by the class and code is contained in functions. The code and data that constitute a class are called members of the class. CRITICAL SKILL The General Form of a Class A .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.