Skip to content

Commit e3627b7

Browse files
committed
Add Shared_pointer example
1 parent 1db1332 commit e3627b7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

APIs_Platform/Shared_pointer/README.md

Whitespace-only changes.

APIs_Platform/Shared_pointer/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "platform/SharedPtr.h"
2+
3+
int main(void)
4+
{
5+
struct MyStruct {
6+
int a;
7+
};
8+
9+
// Create shared pointer
10+
SharedPtr<MyStruct> ptr(new MyStruct);
11+
12+
// Increase reference count
13+
SharedPtr<MyStruct> ptr2(ptr);
14+
15+
ptr = nullptr; // Reference to the struct instance is still held by ptr2
16+
17+
ptr2 = nullptr; // The raw pointer is freed
18+
}

0 commit comments

Comments
 (0)