mirror of
https://github.com/mortennobel/cpp-cheatsheet.git
synced 2024-07-14 16:20:28 +03:00
Merge pull request #4 from iskhanba/master
Fix typo s/Deference/Dereference
This commit is contained in:
commit
1c722499d7
@ -310,7 +310,7 @@ using namespace N; // Make T visible without N::
|
||||
shared_ptr<int> x; // Empty shared_ptr to a integer on heap. Uses reference counting for cleaning up objects.
|
||||
x = make_shared<int>(12); // Allocate value 12 on heap
|
||||
shared_ptr<int> y = x; // Copy shared_ptr, implicit changes reference count to 2.
|
||||
cout << *y; // Deference y to print '12'
|
||||
cout << *y; // Dereference y to print '12'
|
||||
if (y.get() == x.get()) { // Raw pointers (here x == y)
|
||||
cout << "Same";
|
||||
}
|
||||
@ -322,8 +322,8 @@ if (y == nullptr) { // Can compare against nullptr (here returns true)
|
||||
cout << "Empty";
|
||||
}
|
||||
y = make_shared<int>(15); // Assign new value
|
||||
cout << *y; // Deference x to print '15'
|
||||
cout << *x; // Deference x to print '12'
|
||||
cout << *y; // Dereference x to print '15'
|
||||
cout << *x; // Dereference x to print '12'
|
||||
weak_ptr<int> w; // Create empty weak pointer
|
||||
w = y; // w has weak reference to y.
|
||||
if (shared_ptr<int> s = w.lock()) { // Has to be copied into a shared_ptr before usage
|
||||
@ -573,4 +573,4 @@ future<int> fut = // result of async function
|
||||
async(launch::async, fib, 4); // start async function in other thread
|
||||
// do some other work
|
||||
cout << fut.get(); // get result of async function. Wait if needed.
|
||||
```
|
||||
```
|
||||
|
@ -295,7 +295,7 @@ using namespace N; // Make T visible without N::
|
||||
shared_ptr<int> x; // Empty shared_ptr to a integer on heap. Uses reference counting for cleaning up objects.
|
||||
x = make_shared<int>(12); // Allocate value 12 on heap
|
||||
shared_ptr<int> y = x; // Copy shared_ptr, implicit changes reference count to 2.
|
||||
cout << *y; // Deference y to print '12'
|
||||
cout << *y; // Dereference y to print '12'
|
||||
if (y.get() == x.get()) { // Raw pointers (here x == y)
|
||||
cout << "Same";
|
||||
}
|
||||
@ -307,8 +307,8 @@ if (y == nullptr) { // Can compare against nullptr (here returns true)
|
||||
cout << "Empty";
|
||||
}
|
||||
y = make_shared<int>(15); // Assign new value
|
||||
cout << *y; // Deference x to print '15'
|
||||
cout << *x; // Deference x to print '12'
|
||||
cout << *y; // Dereference x to print '15'
|
||||
cout << *x; // Dereference x to print '12'
|
||||
weak_ptr<int> w; // Create empty weak pointer
|
||||
w = y; // w has weak reference to y.
|
||||
if (shared_ptr<int> s = w.lock()) { // Has to be copied into a shared_ptr before usage
|
||||
@ -527,4 +527,4 @@ thread t3(pingPongFn, "boing");
|
||||
future<int> fut = // result of async function
|
||||
async(launch::async, fib, 4); // start async function in other thread
|
||||
// do some other work
|
||||
cout << fut.get(); // get result of async function. Wait if needed.
|
||||
cout << fut.get(); // get result of async function. Wait if needed.
|
||||
|
Loading…
Reference in New Issue
Block a user