Đang chuẩn bị liên kết để tải về tài liệu:
Module 8 Classes and Objects
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'module 8 classes and objects', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Modules Classes and Objects Table of Contents CRITICAL SKILL 8.1 The General Form of a Class.2 CRITICAL SKILL 8.2 Defining a Class and Creating Objects.2 CRITICAL SKILL 8.3 Adding Member Functions to a Class.6 Project 8-1 Creating a Help Class.9 CRITICAL SKILL 8.4 Constructors and Destructors.14 CRITICAL SKILL 8.5 Parameterized Constructors.17 CRITICAL SKILL 8.6 Inline Functions.22 CRITICAL SKILL 8.7 Arrays of Objects.31 CRITICAL SKILL 8.8 Initializing Object Arrays.32 CRITICAL SKILL 8.9 Pointers to Objects.34 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 8.1 The General Form of a Class A .