- Examples
The following examples explain the common usage of smart pointers in embedded programming.
We'll cover the following...
We'll cover the following...
Example 1
To get a visual idea of the life cycle of the resource, there is a short message in the constructor and destructor of MyInt (line 8 - 16).
Explanation
-
In line 22, we create
MyInt(1998), which is the resource that the smart pointer should address. By usingsharPtr->val, we have direct access to the resource (line 23). -
The output of the program shows the numbers of the reference counter. It starts in line 24 with 1. It then has a local copy
shartPtrin line 28 and goes to 2. ...