-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototype.cpp
More file actions
54 lines (45 loc) · 1.25 KB
/
Prototype.cpp
File metadata and controls
54 lines (45 loc) · 1.25 KB
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
/**
* \file Prototype.cpp
* \brief Prototype - object which is cloneable
*
* A Prototype is an object which is cloneable, i.e. you can create a copy,
* even though you don't know what you are creating a copy of.
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
class ICloneable
{
public:
ICloneable() = default;
virtual ~ICloneable() = default;
virtual std::unique_ptr<ICloneable> clone() const = 0;
virtual void test() = 0;
};
//-------------------------------------------------------------------------------------------------
class HelloWorld :
public ICloneable
{
public:
std::unique_ptr<ICloneable> clone() const override
{
return std::unique_ptr<ICloneable>(new HelloWorld);
}
void test() override
{
std::cout << "Hello world!" << std::endl;
}
};
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
HelloWorld hw;
std::unique_ptr<ICloneable> hwClone = hw.clone();
hwClone->test();
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
Hello world!
#endif