Debugging C++ Applications Using HP WDB (766162-001, March 2014)
Example 10 Sample Program and Output Log for Debugging Namespaces
1 #include <iostream>
2 using namespace std;
3
4 char x = 'a';
5 char y = 'b';
6 void func(void){
7 printf("I am global.\n");
8 }
9
10 namespace first
11 {
12 int x = 5;
13 int y = 10;
14 void func(void){
15 printf("I am first.\n");
16 }
17 }
18
19 namespace second
20 {
21 double x = 3.1416;
22 double y = 2.7183;
23 void func(void){
24 printf("I am second.\n");
25 }
26 }
27
28 int main () {
29 using namespace first;
30 using namespace second;
31 cout << first::y << endl;
32 cout << second::x << endl;
33 return 0;
34 }
The WDB output snippet for this program is as shown below:
(gdb) r
Starting program: /user/C++WhitePaper/t/namespace
Breakpoint 1, main () at namespace.C:31
31 cout << first::y << endl;
(gdb) p x
[1] x
[2] first::x
[3] second::x
> 1
$1 = 97 'a'
(gdb) ptype x
[1] x
[2] first::x
[3] second::x
> 1
type = char
(gdb) whatis y
[1] y
[2] first::y
[3] second::y
> 2
variable is: first::y
type = int
18