-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (40 loc) · 991 Bytes
/
main.cpp
File metadata and controls
51 lines (40 loc) · 991 Bytes
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
#include "char_a_factory.hpp"
#include "char_b_factory.hpp"
#include <cassert>
#include <iostream>
std::unique_ptr< BaseChar > createChar( BaseCharFactory & _factory );
std::string enumToString( CharKind _kind );
int main()
{
CharAFactory factoryA;
CharBFactory factoryB;
char c;
std::cin >> c;
std::unique_ptr< BaseChar > currentObject;
if( c == 'a' )
currentObject = createChar( factoryA );
else
currentObject = createChar( factoryB );
assert( currentObject );
std::cout << "Enum : " << enumToString( currentObject->getKind() ) << '\n';
return 0;
}
std::unique_ptr< BaseChar > createChar( BaseCharFactory & _factory )
{
return _factory.createObject();
}
std::string enumToString( CharKind _kind )
{
static_assert( static_cast< int >( CharKind::Count ) == 2, "" );
switch( _kind )
{
case CharKind::A:
return "CharKind::A";
case CharKind::B:
return "CharKind::B";
case CharKind::Count:
return "CharKind::Count";
}
assert( false );
return "";
}