cpp smart pointers code example
Example 1: c++ make shared_ptr
#include <memory>
std::shared_ptr<int> foo = std::make_shared<int> (10);
Example 2: smart pointer c++
void my_func()
{
int* valuePtr = new int(15);
int x = 45;
// ...
if (x == 45)
return; // here we have a memory leak, valuePtr is not deleted
// ...
delete valuePtr;
}
int main()
{
}