summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.robertl/eb17.C
blob: 4163399fba8224d14b70eec5aac47e06b9f91b24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// { dg-do run  }
#include <stdio.h>

class A {
public:
    virtual void print();
    virtual A * clone();
};

struct Pad {
  virtual void f () {}
};

class B : public Pad, virtual public A {
public:
    void print();
    B * clone();
};

void A::print()
{
    printf("A\n");
}

void B::print()
{
    printf("B\n");
}


A * A::clone()
{
    return this;
}

B * B::clone()
{
    return this;
}


int main()
{
    A * a = new B;
    B * b = dynamic_cast<B *>(a);

    printf("%p\n",b);                // (*2*)
    b->print();

    a = b;
    printf("%p\n",a);
    a->print();

    a = a->clone();
    printf("%p\n",a);
    a->print();                      // (*1*)

    return 0;
}