blob: e20a43dff0ba64ea224028cbfaa2625824abcb6e (
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
|
#include <iostream>
#include <vector>
class Base {
public:
virtual void
f()
{
std::cout << "Base\n";
}
};
class Derived: public Base {
public:
virtual void
f()
{
std::cout << "Derived\n";
}
};
int
main()
{
std::vector<Base> s;
Base a;
s.push_back(a);
Derived b;
s.push_back(b);
for (std::vector<Base>::iterator it = s.begin(); it != s.end(); ++it)
it->f();
return 0;
}
|