1 | #include <stdio.h> |
2 | |
3 | namespace Foo |
4 | { |
5 | namespace Bar |
6 | { |
7 | class Baz |
8 | { |
9 | public: |
10 | Baz (int value):m_value(value) {} |
11 | int Function () |
12 | { |
13 | printf (format: "%s returning: %d.\n" , __FUNCTION__, m_value); |
14 | return m_value + 1; |
15 | } |
16 | private: |
17 | int m_value; |
18 | }; |
19 | |
20 | class Baz2 |
21 | { |
22 | public: |
23 | Baz2 (int value):m_value(value) {} |
24 | int Function () |
25 | { |
26 | printf (format: "%s returning: %d.\n" , __FUNCTION__, m_value); |
27 | return m_value + 2; |
28 | } |
29 | private: |
30 | int m_value; |
31 | }; |
32 | |
33 | static int bar_value = 20; |
34 | int Function () |
35 | { |
36 | printf (format: "%s returning: %d.\n" , __FUNCTION__, bar_value); |
37 | return bar_value + 3; |
38 | } |
39 | } |
40 | } |
41 | |
42 | class Baz |
43 | { |
44 | public: |
45 | Baz (int value):m_value(value) {} |
46 | int Function () |
47 | { |
48 | printf (format: "%s returning: %d.\n" , __FUNCTION__, m_value); |
49 | return m_value + 4; |
50 | } |
51 | private: |
52 | int m_value; |
53 | }; |
54 | |
55 | int |
56 | Function () |
57 | { |
58 | printf (format: "I am a global function, I return 333.\n" ); |
59 | return 333; |
60 | } |
61 | |
62 | int main () |
63 | { |
64 | Foo::Bar::Baz mine(200); |
65 | Foo::Bar::Baz2 mine2(300); |
66 | ::Baz bare_baz (500); |
67 | |
68 | printf (format: "Yup, got %d from Baz.\n" , mine.Function()); |
69 | printf (format: "Yup, got %d from Baz.\n" , mine2.Function()); |
70 | printf (format: "Yup, got %d from Baz.\n" , bare_baz.Function()); |
71 | printf (format: "And got %d from Bar.\n" , Foo::Bar::Function()); |
72 | printf (format: "And got %d from ::.\n" , ::Function()); |
73 | |
74 | return 0; |
75 | |
76 | } |
77 | |