-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConstructorsSample.cpp
87 lines (71 loc) · 2.48 KB
/
ConstructorsSample.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
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
#include <iostream>
#include <ostream>
#include "IceCreamSundae.h"
#include "Flavor.h"
#include "Toppings.h"
#include "../pchar.h"
using namespace Desserts;
using namespace std;
typedef Desserts::Toppings::ToppingsList ToppingsList;
int _pmain(int /*argc*/, _pchar* /*argv*/[]) {
const wchar_t* outputPrefixStr = L"Current Dessert: ";
IceCreamSundae s1 = Flavor::Vanilla;
// OUTPUT:
// Conversion constructing IceCreamSundae(Flavor).
wcout << outputPrefixStr << s1.GetSundaeDescription() << endl;
// OUTPUT:
// Current Dessert: A Vanilla sundae with the following toppings: None
s1.AddTopping(ToppingsList::HotFudge);
wcout << outputPrefixStr << s1.GetSundaeDescription() << endl;
// OUTPUT:
// Current Dessert: A Vanilla sundae with the following toppings: Hot Fudge
s1.AddTopping(ToppingsList::Cherry);
wcout << outputPrefixStr << s1.GetSundaeDescription() << endl;
// OUTPUT:
// Current Dessert: A Vanilla sundae with the following toppings:
// Hot Fudge Cherry
s1.AddTopping(ToppingsList::CrushedWalnuts);
wcout << outputPrefixStr << s1.GetSundaeDescription() << endl;
// OUTPUT:
// Current Dessert: A Vanilla sundae with the following toppings:
// Hot Fudge Crushed Walnuts Cherry
s1.AddTopping(ToppingsList::WhippedCream);
wcout << outputPrefixStr << s1.GetSundaeDescription() << endl;
// OUTPUT:
// Current Dessert: A Vanilla sundae with the following toppings:
// Hot Fudge Crushed Walnuts Whipped Cream Cherry
s1.RemoveTopping(ToppingsList::CrushedWalnuts);
// OUTPUT:
// Current Dessert: A Vanilla sundae with the following toppings:
// Hot Fudge Whipped Cream Cherry
wcout << outputPrefixStr << s1.GetSundaeDescription() << endl;
wcout << endl << L"Copy constructing s2 from s1." << endl;
// OUTPUT:
// Copy constructing s2 from s1.
IceCreamSundae s2(s1);
// OUTPUT:
// Copy constructing IceCreamSundae.
wcout << endl << L"Copy assignment to s1 from s2." << endl;
// OUTPUT:
// Copy assignment to s1 from s2.
s1 = s2;
// OUTPUT:
// Copy assigning IceCreamSundae.
wcout << endl << L"Move constructing s3 from s1." << endl;
// OUTPUT:
// Move constructing s3 from s1.
IceCreamSundae s3(std::move(s1));
// OUTPUT:
// Move constructing IceCreamSundae.
// Move assigning IceCreamSundae.
wcout << endl << L"Move assigning to s1 from s2." << endl;
// OUTPUT:
// Move assigning to s1 from s2.
s1 = std::move(s2);
// OUTPUT:
// Move assigning IceCreamSundae.
// Destroying IceCreamSundae.
// Destroying IceCreamSundae.
// Destroying IceCreamSundae.
return 0;
}