-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathobject_construction.cpp
More file actions
98 lines (69 loc) · 2.04 KB
/
object_construction.cpp
File metadata and controls
98 lines (69 loc) · 2.04 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//*****************************************************************************
//
// Author: Michael Price
// License: Attribution-NonCommercial-NoDerivs 3.0 Unported
// http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode
//
//*****************************************************************************
#ifndef WIN32
namespace std {
class string { public: string(const char *) { } string operator+(string other) { return other; } };
}
#endif // WIN32
#define THING_VER 2
class SomeComplicatedThing
{
#if THING_VER == 1 ////////////////////////////////////////////////////////////
public:
SomeComplicatedThing ()
: m_one(1)
, m_two(2.0)
, m_three("Three")
{ init(false); }
SomeComplicatedThing (bool make_square)
: m_one(1)
, m_two(2.0)
, m_three("Three")
{ init(make_square); }
private:
int m_one;
double m_two;
std::string m_three;
void init (bool make_square)
{ if (make_square) m_two = m_one * m_one; }
#elif THING_VER == 2 //////////////////////////////////////////////////////////
public:
SomeComplicatedThing ()
{ init(false); }
SomeComplicatedThing (bool make_square)
{ init(make_square); }
private:
int m_one = 1;
double m_two = 2.0;
std::string m_three = "Three";
void init (bool make_square)
{ if (make_square) m_two = m_one * m_one; }
#elif THING_VER == 3 //////////////////////////////////////////////////////////
public:
SomeComplicatedThing ()
: SomeComplicatedThing(false)
{ }
SomeComplicatedThing (bool make_square)
{ if (make_square) m_two = m_one * m_one; }
private:
int m_one = 1;
double m_two = 2.0;
std::string m_three = "Three";
#endif // THING_VER == ? //////////////////////////////////////////////////////
};
class SomeDerivedThing : public SomeComplicatedThing
{
public:
// using SomeComplicatedThing::SomeComplicatedThing;
void anotherMethodHere () { }
};
void ctorInheritance ()
{
SomeDerivedThing sdt;
// SomeDerivedThing multiplied_sdt(true);
}