Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Absolute C++ (4th Edition) part 46. 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. . | n Separate Compilation and Namespaces CHAPTER SUMMARY 495 ANSWERS TO SELF-TEST EXERCISES 495 PROGRAMMING PROJECTS 497 ll.l SEPARATE COMPILATION 458 Encapsulation Reviewed 459 Header Files and Implementation Files 460 Example DigitalTime Class 468 Tip Reusable Components 469 Using ifndef 469 Tip Defining Other Libraries 472 11.2 NAMESPACES 473 Namespaces and using Directives 473 Creating a Namespace 475 Using Declarations 478 Qualifying Names 480 Example A Class Definition in a Namespace 482 Tip Choosing a Name for a Namespace 482 Unnamed Namespaces 484 Pitfall Confusing the Global Namespace and the Unnamed Namespace 490 Tip Unnamed Namespaces Replace the static Qualifier 491 Tip Hiding Helping Functions 491 Nested Namespaces 491 Tip What Namespace Specification Should You Use 492 Separate Compilation and Namespaces From mine own library with volumes that I prize above my dukedom. William Shakespeare The Tempest Introduction This chapter covers two topics that have to do with how to organize a C program into separate parts. Section 11.1 on separate compilation discusses how a C program can be distributed across a number of files so that when some parts of the program change only those parts need to be recompiled and so that the separate parts can be more easily reused in other applications. Section 11.2 discusses namespaces which were introduced briefly in Chapter 1. Namespaces are a way of allowing you to reuse the names of classes functions and other items by qualifying the names to indicate different uses. Namespaces divide your code into sections so that the different sections may reuse the same names with differing meanings. They allow a kind of local meaning for names that is more general than local variables. This chapter can be covered earlier than its location in the book. This chapter does not use any of the material from Chapters 5 arrays 9 strings 10 pointers and dynamic arrays or Section 7.3 vectors of Chapter 7. n.i Separate Compilation Your if is the