summaryrefslogtreecommitdiff
path: root/tests/exec/redef2.cpp
blob: 49b06e26a117e42a444662ad69d1a3f2e422df7e (plain) (blame)
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
#include <iostream>

class A {
public:
  virtual int f(int x);
};

int A::f(int x) { return x; }

class B : public A {
public:
};

class C : public B {
public:
  virtual int f(int x);
};

int C::f(int x) { return 3*x; }

int main() {
  A *a = new A();
  std::cout << a->f(1) << "\n";
  B *b = new B();
  std::cout << b->f(1) << "\n";
  C *c = new C();
  std::cout << c->f(1) << "\n";
  a = b;
  std::cout << a->f(1) << "\n";
  a = c;
  std::cout << a->f(1) << "\n";
  b = c;
  std::cout << b->f(1) << "\n";
}