We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 731d3db commit 8bbe4a3Copy full SHA for 8bbe4a3
08-exceptions/myvec-demo/controllable.hh
@@ -1,15 +1,17 @@
1
#pragma once
2
3
#include <iostream>
4
+#include <memory>
5
#include <stdexcept>
6
#include <utility>
7
-struct Controllable {
8
+struct Controllable final {
9
static int control;
- int *resource_;
10
+ std::unique_ptr<int> resource_;
11
Controllable() : resource_(new int(42)) {}
12
- Controllable(Controllable &&rhs) noexcept : resource_(rhs.resource_) {
13
+ Controllable(Controllable &&rhs) noexcept
14
+ : resource_(std::move(rhs.resource_)) {
15
rhs.resource_ = nullptr;
16
}
17
Controllable &operator=(Controllable &&rhs) noexcept {
@@ -30,5 +32,5 @@ struct Controllable {
30
32
return *this;
31
33
34
- ~Controllable() { delete resource_; }
35
+ ~Controllable() = default;
36
};
0 commit comments