Sams Teach Yourself C++ in 21 Days
Q My friends use printf()in their C++ programs. Can I? A No. At this point,printf()should properly be considered obsolete. Works ...
DAY 18 WEEK 3 Creating and Using Namespaces Namespaces can be used to help you organize your classes. More importantly, namespac ...
found in different library packages. For example, a container class library will almost certainly declare and implement a Listcl ...
Creating and Using Namespaces 639 18 LISTING18.1A First Listing Using integerValue 0: // file first.cpp 1: int integerValue = 0 ...
LISTING18.2B Second Listing for Identifier Hiding 0: // file second.cpp 1: int integerValue = 0 ; 2: // end of second.cpp 640 Da ...
Creating and Using Namespaces 641 18 The first intdefinition,globalScopeInt, on line 1 is visible within the functions f()and ma ...
The externalIntvariable defined on line 1 of first.cpp (Listing 18.4a) has external linkage. Although it is defined in first.cpp ...
Creating and Using Namespaces 643 18 DOuse namespaces instead of static global variables. DON’Tapply the statickeyword to a vari ...
LISTING18.6B Grouping Related Items 0: // header2.h 1: namespace Window 2: { 3: void resize( int x, int y ) ; 4: } As you can se ...
Creating and Using Namespaces 645 18 Defining Functions Outside a Namespace .................................................... ...
When you add new members, you do not want to include access modifiers, such as pub- lic or private. All members encased within a ...
Creating and Using Namespaces 647 18 4: { 5: const int MAX_X = 30 ; 6: const int MAX_Y = 40 ; 7: class Pane 8: { 9: public: 10: ...
x 20 y 20 Note that class Paneon lines 7–19 is nested inside the namespace Window, which is on lines 3–20. This is the reason yo ...
Creating and Using Namespaces 649 18 namespace Window { int value1 = 20 ; int value2 = 40 ; } ... Window::value1 = 10 ; using na ...
int value1 = 20 ; int value2 = 40 ; } //... void f() { int value2 = 10 ; using namespace Window ; std::cout << value2 < ...
Creating and Using Namespaces 651 18 int value3 = 60 ; } //... using Window::value2 ; //bring value2 into current scope Window:: ...
{ using Window::value2 ; std::cout << value2 << std::endl ; } The usingdeclaration in f()hides the value2defined in ...
Creating and Using Namespaces 653 18 LISTING18.9A An Unnamed Namespace 0: // file: one.cpp 1: namespace 2: { 3: int value ; 4: c ...
The Standard Namespace std.............................................................................. The best example of nam ...
Creating and Using Namespaces 655 18 As an alternative, you could fully qualify the names that you use, as in Listing 18.11. LIS ...
«
29
30
31
32
33
34
35
36
37
38
»
Free download pdf