mirror of
https://github.com/mortennobel/cpp-cheatsheet.git
synced 2024-09-11 13:06:55 +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.
|
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
|
x = make_shared<int>(12); // Allocate value 12 on heap
|
||||||
shared_ptr<int> y = x; // Copy shared_ptr, implicit changes reference count to 2.
|
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)
|
if (y.get() == x.get()) { // Raw pointers (here x == y)
|
||||||
cout << "Same";
|
cout << "Same";
|
||||||
}
|
}
|
||||||
@ -322,8 +322,8 @@ if (y == nullptr) { // Can compare against nullptr (here returns true)
|
|||||||
cout << "Empty";
|
cout << "Empty";
|
||||||
}
|
}
|
||||||
y = make_shared<int>(15); // Assign new value
|
y = make_shared<int>(15); // Assign new value
|
||||||
cout << *y; // Deference x to print '15'
|
cout << *y; // Dereference x to print '15'
|
||||||
cout << *x; // Deference x to print '12'
|
cout << *x; // Dereference x to print '12'
|
||||||
weak_ptr<int> w; // Create empty weak pointer
|
weak_ptr<int> w; // Create empty weak pointer
|
||||||
w = y; // w has weak reference to y.
|
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
|
if (shared_ptr<int> s = w.lock()) { // Has to be copied into a shared_ptr before usage
|
||||||
|
@ -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.
|
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
|
x = make_shared<int>(12); // Allocate value 12 on heap
|
||||||
shared_ptr<int> y = x; // Copy shared_ptr, implicit changes reference count to 2.
|
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)
|
if (y.get() == x.get()) { // Raw pointers (here x == y)
|
||||||
cout << "Same";
|
cout << "Same";
|
||||||
}
|
}
|
||||||
@ -307,8 +307,8 @@ if (y == nullptr) { // Can compare against nullptr (here returns true)
|
|||||||
cout << "Empty";
|
cout << "Empty";
|
||||||
}
|
}
|
||||||
y = make_shared<int>(15); // Assign new value
|
y = make_shared<int>(15); // Assign new value
|
||||||
cout << *y; // Deference x to print '15'
|
cout << *y; // Dereference x to print '15'
|
||||||
cout << *x; // Deference x to print '12'
|
cout << *x; // Dereference x to print '12'
|
||||||
weak_ptr<int> w; // Create empty weak pointer
|
weak_ptr<int> w; // Create empty weak pointer
|
||||||
w = y; // w has weak reference to y.
|
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
|
if (shared_ptr<int> s = w.lock()) { // Has to be copied into a shared_ptr before usage
|
||||||
|
Loading…
Reference in New Issue
Block a user