Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Absolute C++ (4th Edition) part 23. 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. . | 6 Structures and Classes CHAPTER SUMMARY 252 ANSWERS TO SELF-TEST EXERCISES 253 PROGRAMMING PROJECTS 255 6.1 STRUCTURES 224 Structure Types 226 Pitfall Forgetting a Semicolon in a Structure Definition 230 Structures as Function Arguments 230 Tip Use Hierarchical Structures 231 Initializing Structures 234 6.2 CLASSES 236 Defining Classes and Member Functions 236 Encapsulation 242 Public and Private Members 243 Accessor and Mutator Functions 247 Tip Separate Interface and Implementation 248 Tip A Test for Encapsulation 249 Structures versus Classes 250 Tip Thinking Objects 252 Structures and Classes The time has come the Walrus said To talk of many things Of shoes and ships and sealing wax Of cabbages and kings. Lewis Carroll Through the Looking Glass Introduction Classes are perhaps the single most significant feature that separates the C language from the C language. A class is a type whose values are called objects. Objects have both data and member functions. The member functions have special access to the data of their object. These objects are the objects of object-oriented programming a very popular and powerful programming philosophy. We will introduce classes in two steps. We first tell you how to give a type structure definition for a structure. A structure of the kind discussed here can be thought of as an object without any member functions.1 The important property of structures is that the data in a structure can be a collection of data items of diverse types. After you learn about structures it will be a natural extension to define classes. You do not need the material on arrays given in Chapter 5 in order to read Chapter 6 and most of Chapters 7 and 8 which cover classes. 6.i Structures I don t care to belong to any club that will accept me as a member. Groucho Marx The Groucho Letters Sometimes it is useful to have a collection of values of different types and to treat the collection as a single item. For example consider a bank certificate of deposit