A data type with dynamically-allocated data.
| 112 | |
| 113 | // A data type with dynamically-allocated data. |
| 114 | struct HeapAllocatedObject { |
| 115 | int* value; |
| 116 | |
| 117 | HeapAllocatedObject() { |
| 118 | value = new int; |
| 119 | *value = kIntElement; |
| 120 | } |
| 121 | |
| 122 | HeapAllocatedObject(const HeapAllocatedObject& other) { |
| 123 | value = new int; |
| 124 | *value = *other.value; |
| 125 | } |
| 126 | |
| 127 | HeapAllocatedObject& operator=(const HeapAllocatedObject& other) { |
| 128 | *value = *other.value; |
| 129 | return *this; |
| 130 | } |
| 131 | |
| 132 | HeapAllocatedObject(HeapAllocatedObject&& other) { |
| 133 | value = other.value; |
| 134 | other.value = nullptr; |
| 135 | } |
| 136 | |
| 137 | ~HeapAllocatedObject() { delete value; } |
| 138 | |
| 139 | bool operator==(const HeapAllocatedObject& other) const { |
| 140 | return *value == *other.value; |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | // Constructs a Foo. |
| 145 | struct FooCtor { |