Syntax

C++ Unique Pointer Syntax

In C++, unique pointer: owns heap memory automatically — auto p = std::make_unique<Dog>("Rex");

Quick Answer

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

Unique Pointer

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

Owns heap memory automatically.

Learn More

How to unique 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++ Unique Pointer Syntax

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

Related Syntax References

Frequently asked questions

What is the C++ syntax for unique pointer?

Use this pattern: auto p = std::make_unique<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