Syntax

C++ Shared Pointer Syntax

In C++, shared pointer: shares ownership of heap memory — auto p = std::make_shared<Dog>("Rex");

Quick Answer

Syntax
auto p = std::make_shared<Dog>("Rex");
C++Syntax

Shared Pointer

Code example
auto p = std::make_shared<Dog>("Rex");

Shares ownership of heap memory.

Learn More

How to shared pointer in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Shared Pointer Syntax

Use auto p = std::make_shared<Dog>("Rex");.

Related Syntax References

Frequently asked questions

What is the C++ syntax for shared pointer?

Use this pattern: auto p = std::make_shared<Dog>("Rex");

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify