2004-02-11 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / member-ptr.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 1998, 1999, 2004 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20
21
22 extern "C" {
23 #include <stdio.h>
24 }
25
26
27 class A {
28 public:
29 A();
30 int foo (int x);
31 int bar (int y);
32 virtual int baz (int z);
33 char c;
34 int j;
35 int jj;
36 static int s;
37 };
38
39 class B {
40 public:
41 static int s;
42 };
43
44 int A::s = 10;
45 int B::s = 20;
46
47 A::A()
48 {
49 c = 'x';
50 j = 5;
51 }
52
53 int A::foo (int dummy)
54 {
55 j += 3;
56 return j + dummy;
57 }
58
59 int A::bar (int dummy)
60 {
61 int r;
62 j += 13;
63 r = this->foo(15);
64 return r + j + 2 * dummy;
65 }
66
67 int A::baz (int dummy)
68 {
69 int r;
70 j += 15;
71 r = this->foo(15);
72 return r + j + 12 * dummy;
73 }
74
75 int fum (int dummy)
76 {
77 return 2 + 13 * dummy;
78 }
79
80 typedef int (A::*PMF)(int);
81
82 typedef int A::*PMI;
83
84 int main ()
85 {
86 A a;
87 A * a_p;
88 PMF pmf;
89
90 PMF * pmf_p;
91 PMI pmi;
92
93 a.j = 121;
94 a.jj = 1331;
95
96 int k;
97
98 a_p = &a;
99
100 pmi = &A::j;
101 pmf = &A::bar;
102 pmf_p = &pmf;
103
104 pmi = NULL;
105
106 k = (a.*pmf)(3);
107
108 pmi = &A::jj;
109 pmf = &A::foo;
110 pmf_p = &pmf;
111
112 k = (a.*pmf)(4);
113
114 k = (a.**pmf_p)(5);
115
116 k = a.*pmi;
117
118
119 k = a.bar(2);
120
121 k += fum (4);
122
123 B b;
124
125 k += b.s;
126
127 }
This page took 0.03411 seconds and 5 git commands to generate.