Absolute C++ (4th Edition) part 48

Absolute C++ (4th Edition) part 48. 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. . | Namespaces 477 Display Namespace Demonstration part 2 of 2 26 27 namespace Spacel 28 29 void greeting 30 31 cout Hello from namespace Space1. n 32 33 34 35 36 37 38 39 40 namespace Space2 void greeting cout Greetings from namespace Space2. n 41 void bigGreeting 42 43 cout A Big Global Hello n 44 Sample Dialogue Greetings from namespace Space2. Hello from namespace Spacel. A Big Global Hello Note that you can have any number of these namespace groupings for a single namespace. In Display we used two namespace groupings for namespace Spacel and two other groupings for namespace Space2. Every name defined in a namespace is available inside the namespace groupings but the names can also be made available to code outside the namespace groupings. For example the function declaration and function definition in the namespace Spacel can be made available with the using directive using namespace Spacel as illustrated in Display . 478 Separate Compilation and Namespaces Putting a Definition in a Namespace You place a name definition in a namespace by placing it in a namespace grouping which has the following syntax namespace Namespace_Name Definitions Definition_2 Definition_Last You can have multiple namespace groupings even in multiple files and all the definitions in all the groupings will be in the same namespace. Self-Test Exercises 6. Consider the program shown in Display . Could we use the name greeting in place ofbigGreeting 7. In Exercise 6 we saw that you could not add a definition for the following function to the global namespace void greeting Can you add a definition for the following function declaration to the global namespace void greeting int howMany using declarations This subsection describes a way to qualify a single name so that you can make only one name from a namespace available to your program rather than making all the names in a namespace available. We saw this technique in Chapter 1 and so this is a review and amplification of .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
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.