Move std::unique_ptr to Pass to a Function or Assign to Another Variable

The std::unique_ptr has unique ownership of the object it manages. That means that more than one std::unique_ptr object can not contain the managed object pointer. That’s why we can not assign a std::unique_ptr to another one. For the same reason, we can not pass std::unique_ptr as an argument of a function. But we can always … Continue reading “Move std::unique_ptr to Pass to a Function or Assign to Another Variable”

Custom Deleter in std::unique_ptr

In my previous article, we discussed how std::unique_ptr helps to avoid memory leak. By default it calls the default deleter (C++ delete operator) when the std::unique_ptr goes out of context. But many times default deleter is not good enough for the type of pointer we deal with. For example, if you work with a file … Continue reading “Custom Deleter in std::unique_ptr”

What is std::unique_ptr? How to Use std::unique_ptr?

std::unique_ptr is a smart pointer that owns and manages another object through pointer. std::unique_ptr has unique ownership of the object. That means only one std::unique_ptr can have the ownership of the actual object. We can not assign a std::unique_ptr object to another smart pointer. std::unique_ptr disposes the managed object when the unique_ptr goes out of … Continue reading “What is std::unique_ptr? How to Use std::unique_ptr?”

How to do Asynchronous Operations using boost::asio?

Boost::asio is primarily designed for accomplishing time-consuming networking I/O (Input/Output) operations in an asynchronous way. I/O operations over network usually takes considerable time to complete. In synchronous mode, if you call a function that does I/O operation over network, the calling thread blocks until the I/O operation is complete. This is not acceptable in many … Continue reading “How to do Asynchronous Operations using boost::asio?”

Compilation Error, Linking Error and Run Time Error

All these types of errors refer to different stages of program’s lifetime. To understand these errors, we have to understand the stages of a program’s lifetime. Generally the programs are written in high level programming languages like C or Fotran which is referred as source codes. Source codes are human readable text that are written in English … Continue reading “Compilation Error, Linking Error and Run Time Error”

0
0
0
0
0
0