Smart Pointers as Pointers

Learn about the relation between const and smart pointers acting as pointers.

There are two ways to approach smart pointers. One way is to consider that smart pointers are effective pointers. Either the pointer or the pointed value can be const. Or both.

In another perspective, we consider that smart pointers are class-type objects. Basically, they are wrapping pointers. As a smart pointer is an object, the rule of thumb says that it can be passed around as a const reference. We are going to see that in most cases, it’s a bad idea.

Let’s examine both perspectives.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy