-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc2.cpp
57 lines (47 loc) · 863 Bytes
/
abc2.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
56
57
#include <fstream>
#include <iostream>
class ABC {
public:
ABC() {}
virtual ~ABC() {}
public:
virtual void printOn(std::ostream &os) const=0;
};
class Imp1 : public ABC {
public:
void printOn(std::ostream &os) const
{
os << "This is an Imp1 instance";
}
};
class Imp2 : public ABC {
public:
void printOn(std::ostream &os) const
{
os << "This is an Imp2 instance";
}
};
template<class T>
class Master {
public:
Master() : abc(new T) {}
virtual ~Master() {}
T *abc;
void printOn(std::ostream &os) const
{
(*abc).printOn(os);
}
void hello() const;
};
class Derived1 : public Master<Imp1> {};
class Derived2 : public Master<Imp2> {};
int main()
{
Derived1 master1;
Derived2 master2;
master1.printOn(std::cout);
std::cout << std::endl;
master2.printOn(std::cout);
std::cout << std::endl;
return 0;
}