| 1 |
#include <stdarg.h> |
| 2 |
#include <assert.h> |
| 3 |
|
| 4 |
class C1 |
| 5 |
{ |
| 6 |
public: |
| 7 |
virtual ~C1(); |
| 8 |
|
| 9 |
int i; |
| 10 |
|
| 11 |
int f0(); |
| 12 |
int f1(int a); |
| 13 |
int f2(int a, int b); |
| 14 |
virtual int f3(int a, int b); |
| 15 |
int f4(int a, ...); |
| 16 |
}; |
| 17 |
|
| 18 |
C1::~C1() |
| 19 |
{ |
| 20 |
} |
| 21 |
|
| 22 |
int C1::f0() |
| 23 |
{ |
| 24 |
return i; |
| 25 |
} |
| 26 |
|
| 27 |
int C1::f1(int a) |
| 28 |
{ |
| 29 |
return i + a; |
| 30 |
} |
| 31 |
|
| 32 |
int C1::f2(int a, int b) |
| 33 |
{ |
| 34 |
return i + a + b; |
| 35 |
} |
| 36 |
|
| 37 |
int C1::f3(int a, int b) |
| 38 |
{ |
| 39 |
return i + a + b; |
| 40 |
} |
| 41 |
|
| 42 |
int C1::f4(int a, ...) |
| 43 |
{ |
| 44 |
int r = i + a; |
| 45 |
int last = a; |
| 46 |
|
| 47 |
va_list argp; |
| 48 |
va_start(argp, a); |
| 49 |
while (last) |
| 50 |
{ |
| 51 |
last = va_arg(argp, int); |
| 52 |
r += last; |
| 53 |
} |
| 54 |
va_end(argp); |
| 55 |
return r; |
| 56 |
} |
| 57 |
|
| 58 |
C1 *createC1() |
| 59 |
{ |
| 60 |
return new C1(); |
| 61 |
} |
| 62 |
|
| 63 |
class C2 |
| 64 |
{ |
| 65 |
public: |
| 66 |
virtual ~C2(); |
| 67 |
|
| 68 |
int i; |
| 69 |
|
| 70 |
int f0(); |
| 71 |
int f1(int a); |
| 72 |
int f2(int a, int b); |
| 73 |
virtual int f3(int a, int b); |
| 74 |
int f4(int a, ...); |
| 75 |
}; |
| 76 |
|
| 77 |
C2 *createC2(); |
| 78 |
|
| 79 |
void runCPPTests() |
| 80 |
{ |
| 81 |
C2 *c2 = createC2(); |
| 82 |
c2->i = 100; |
| 83 |
assert(c2->f0() == 100); |
| 84 |
assert(c2->f1(1) == 101); |
| 85 |
assert(c2->f2(20, 3) == 123); |
| 86 |
assert(c2->f3(20, 3) == 123); |
| 87 |
assert(c2->f4(20, 3, 0) == 123); |
| 88 |
|
| 89 |
int (C2::*fp0)() = &C2::f0; |
| 90 |
int (C2::*fp1)(int) = &C2::f1; |
| 91 |
int (C2::*fp2)(int, int) = &C2::f2; |
| 92 |
int (C2::*fp3)(int, int) = &C2::f3; |
| 93 |
int (C2::*fp4)(int, ...) = &C2::f4; |
| 94 |
assert((c2->*(fp0))() == 100); |
| 95 |
assert((c2->*(fp1))(1) == 101); |
| 96 |
assert((c2->*(fp2))(20, 3) == 123); |
| 97 |
assert((c2->*(fp3))(20, 3) == 123); |
| 98 |
assert((c2->*(fp4))(20, 3, 0) == 123); |
| 99 |
} |