gcc/testsuite/g++.old-deja/g++.law/virtual4.C
raw| 1 | // { dg-do run } |
| 2 | // GROUPS passed virtual-functions |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | int aset = 0; |
| 7 | class A |
| 8 | { |
| 9 | public: |
| 10 | void Set() { SetProp(); } |
| 11 | virtual void SetProp() { aset++;} |
| 12 | }; |
| 13 | |
| 14 | class B:public A |
| 15 | { |
| 16 | public: |
| 17 | void SetProp() { if (!aset) { printf ("FAIL\n"); exit (1);} aset--;} |
| 18 | }; |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | A a; |
| 23 | B b; |
| 24 | A *c=new A; |
| 25 | A *d=new B; |
| 26 | |
| 27 | a.Set(); |
| 28 | b.Set(); |
| 29 | c->Set(); |
| 30 | d->Set(); |
| 31 | printf ("PASS\n"); |
| 32 | } |