Skip to content

Commit 982c1f6

Browse files
committed
fix errors
1 parent c8dc81f commit 982c1f6

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

content/posts/cpp-for-cscharp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ This pointer has ownership over whatever it points to, if it goes out of scope a
116116
What makes this one different from the other smart pointers:
117117

118118
- there can only be only one unique pointer per object
119-
- the pointer and the object have the same lifetime
119+
- the object lifetime is tied to the unique pointer, unless ownership is moved
120120

121121
```cpp
122122
// cpp
@@ -152,15 +152,15 @@ void test()
152152
std::shared_ptr<Foo> sp_1 = std::make_shared<Foo>();
153153

154154
// sharing ownership
155-
std::shared_ptr<int> sp_2 = sp_1;
155+
std::shared_ptr<Foo> sp_2 = sp_1;
156156

157157
// get amount of shares
158-
int shares = sp_1.use_count() // there are now 2 shares
158+
int shares = sp_1.use_count(); // there are now 2 shares
159159

160160
// you can manually drop a share like so
161161
sp_2.reset();
162162

163-
int shares = sp_1.use_count() // there is now 1 share
163+
int shares = sp_1.use_count(); // there is now 1 share
164164

165165
// at the end of this scope the first pointer also drops
166166
// now since there are no more shares the object is freed
@@ -194,7 +194,7 @@ void test()
194194
std::weak_ptr<Foo> wp = sp;
195195

196196
// get amount of shares
197-
int shares = sp.use_count() // still 1, weak ptr didnt add a share
197+
int shares = sp.use_count(); // still 1, weak ptr didnt add a share
198198

199199
// destroy the only and last shared pointer with ownership
200200
sp.reset();

0 commit comments

Comments
 (0)