-
Notifications
You must be signed in to change notification settings - Fork 0
/
T.cpp
55 lines (49 loc) · 886 Bytes
/
T.cpp
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
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
template <typename T>
T prod(T a, T b){ return a * b; }
#define PROD(a,b)(a*b)
#define DIV(b,c)(b / c)
using namespace std;
typedef int (*ifi)(int);
class Base
{
public:
Base( int i = 42 )
: i(i) { }
virtual void out()
{ cout << "Base: " << i << endl; }
protected:
int i;
};
class Sub : public Base
{
public:
Sub( int i = 21, int j = 53 )
: j(j), Base(i) { }
virtual void out()
{ cout << "Sub: " << i << ", " << j << endl; }
protected:
int j;
};
int main()
{
Base* ap[5];
ap[0] = new Sub( );
ap[1] = new Sub( 3 );
ap[2] = new Sub( 5, 6 );
ap[3] = new Base();
ap[4] = new Base( 8 );
for( int i=0 ; i < 5 ; i++ )
ap[i]->out();
vector<Base> v(5);
for( int i=0 ; i < 5 ; i++ )
v[i] = *ap[i];
for( int i=0 ; i < 5 ; i++ )
v[i].out();
system("pause");
return 0;
}