In comparison to a raw pointer, shared_ptr provides only these operators

1.) -> , *
2.)  Comparison Operators

It doesn’t provide,
1.)  Pointer arithmetic like +, -, ++, —
2.)  Operator []

Checkout below example,

When we create shared_ptr object without assigning any value then its empty.
With shared_ptr user can check for emptiness like this,

We can also access the internal raw pointer from shared_ptr object like this,

Ideally we should not use this because it can cause problem if we delete this pointer by mistake. In that case when shared_ptr object will go out of scope then it will try to delete already deleted memory and it will create our program to crash. We will discuss this in more detail in next post.

Click Here to Subscribe for more Articles / Tutorials like this.