C++ 11

How to use unique_ptr with Arrays in C++?

In Modern C++, we can create unique_ptr object to manage dynamically allocated arrays. However, the syntax for using std::unique_ptr with arrays is a bit different. In this article, we will look into this in more detail. Syntax to use unique_ptr with Arrays When you want a create a unique_ptr object to manage a dynamically allocated […]

How to use unique_ptr with Arrays in C++? Read More »

How to Return unique_ptr from a function in C++?

Returning a unique_ptr from a function is a common and recommended practice when you want to transfer ownership of dynamically allocated objects without the risk of memory leaks. Here is how you can return a unique_ptr from a function in C++. Returning a unique_ptr Directly C++ supports Return Value Optimization (RVO) and move semantics, which

How to Return unique_ptr from a function in C++? Read More »

Reset unique_ptr in Modern C++

When working with unique_ptr in C++, it’s essential to know how to renounce the ownership of the managed object and free the associated memory when necessary. The unique_ptr class provides the reset() member function for this purpose. The unique_ptr::reset() Function Calling the reset() method on a unique_ptr will perform two operations: Example of reset() function

Reset unique_ptr in Modern C++ Read More »

Introduction to Smart Pointers in Modern C++

Smart Pointers were introduced by C++11 Standard. Smart pointers are a significant advancement that addresses the longstanding challenge of memory management in C++ programming. The Problem of Memory Management Traditionally, managing memory in C++ has involved two primary operations: allocating memory with the new operator and releasing it using the delete operator. This manual process

Introduction to Smart Pointers in Modern C++ Read More »

How to Delete a Function in C++11 / 14?

In modern C++, the ‘delete’ keyword plays a crucial role in enhancing code safety and correctness. Introduced in C++11, this powerful feature allows programmers to explicitly forbid the use of certain functions, including automatically generated ones like default constructors and assignment operators. In this article, we will explore the practical applications of the ‘delete’ keyword

How to Delete a Function in C++11 / 14? Read More »

Scroll to Top