-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathName Visibility 2_4.cpp
65 lines (46 loc) · 1.9 KB
/
Name Visibility 2_4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
using namespace std;
namespace hair
{
int greg() { return 50; } //need that () for some reason if it's formated like this
int waffle = 4;
}
namespace car
{
double whip = 67.4; //compare to formating above, can do it both ways (Notice the middle bar declaring the scope when you click in this area)
int waffle = 4000000;
}
int main() {
{
cout << "Quick waffle: \n";
using namespace car;
cout << waffle << "\n"; // Could put this lower but I declared waffle as 10 below this, now it will always be 10 even if I lower this
using hair::waffle;
cout << waffle << "\n";
}
cout << "\n---------------------------------------------------\n\n";
int waffle = 10;
int cart = 20;
{
int waffle;
waffle = 7; // waffle in the inner scope is now my favorite number
cart = 9000; // This will affect the outer scope as well
cout << "Inner block => \n";
cout << waffle << "\n"; // output will be 7
cout << cart << "\n"; // output will be 9000
}
cout << "\nOuter block => \n";
cout << waffle << "\n"; // output will be 10
cout << cart << "\n"; // output will be 9000 still because cart wasn't re-declared in that local block
cout << "\n---------------------------------------------------\n\n"; // code below this refers to the two namespaces above
cout << "Referring to the namespaces here\n";
cout << hair::greg() << "\n";
cout << car::whip << "\n";
cout << "\n---------------------------------------------------\n\n";
cout << "Different ways to output a waffle (other than a toaster LOL)\n";
cout << waffle << "\n";
cout << car::waffle << "\n"; // notice how the car waffle refers to the namespace and the value above is the global setting
cout << "\n---------------------------------------------------\n\n";
cin.get(); // so that "press any key to continue" doesn't show up in the console
}