TAILIEUCHUNG - A Complete Guide to Programming in C++ part 24

A Complete Guide to Programming in C++ part 24. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | NAMESPACES 209 Using global names in large-scale software projects can lead to conflicts especially when multiple class libraries are in operation. C provides for the use of namespaces in order to avoid naming conflicts with global identifiers. Within a namespace you can use identifiers without needing to check whether they have been defined previously in an area outside of the namespace. Thus the global scope is subdivided into isolated parts. A normal namespace is identified by a name preceded by the namespace keyword. The elements that belong to the namespace are then declared within braces. Example namespace myLib int count double calculate double int . . . This example defines the namespace myLib that contains the variable count and the function calculated . Elements belonging to a namespace can be referenced directly by name within the namespace. If you need to reference an element from outside of the namespace you must additionally supply the namespace. To do so place the scope resolution operator before the element name. Example myLib count 7 Outside of myLib This allows you to distinguish between identical names in different namespaces. You can also use the scope resolution operator to reference global names that is names declared outside of any namespaces. To do so simply omit the name of the namespace. This technique is useful when you need to access a global name that is hidden by an identical name defined in the current namespace. Example demo Not belonging to any namespace Be aware of the following when using namespaces namespaces do not need to be defined contiguously. You can reopen and expand a namespace you defined previously at any point in the program namespaces can be nested that is you can define a namespace within another namespace. Global identifiers belonging to the C standard library automatically belong to the standard namespace std. 210 CHAPTER 1 1 ST0RAGE CLASSES AND NAMESPACES THE KEYWORD using Sample program Demonstrates .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.