summaryrefslogtreecommitdiff
path: root/c,cc/slicing.cc
blob: c89d99d749c52aee3e7aca6b8394e65dc5547174 (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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct A {
  public:
    virtual string s() { return "a"; }
};

class B : public A {
  public:
    string s() { return "b"; }
};

B
make_b()
{
  B b;
  return b;
}

A
make_a()
{
  return make_b();
}

int
main(void)
{
  vector<A> x;
  B b = make_b();
  x.push_back(b);
  cout << x[0].s() << endl;
  B c;
  x.push_back(c);
  cout << x[1].s() << endl;

  return 0;
}