std::forward, Perfect Forwarding of Parameters

C++11 introduced the std::forward to preserve the value category (lvalue or rvalue) of a cv-unqualified function template parameter, that is declared as an rvalue reference, in time of passing that to another function. It forwards an lvalue either as an lvalue or as an rvalue depending on the deduced type of the template parameter. Apparently … Continue reading “std::forward, Perfect Forwarding of Parameters”

Assignment Operator Overloading in C++

In C++, we can overload an operator for a user defined class to change its default behavior. C++ provides a default assignment operator, “=”, that provides member by member copy. This default behavior of the assignment operator does not always produce desired result. The default assignment operator has the exact same problem that a default … Continue reading “Assignment Operator Overloading in C++”

Move Assignment Operator in C++

Just like a move constructor, the move assignment operator also makes a class movable. A movable class enables efficient resource transfer from one object to another. Let’s start with an normal overloaded assignment operator. In this example, we overloaded the assignment operator in the mystring class. This overloaded function was called the object s2 was … Continue reading “Move Assignment Operator in C++”

Move Constructor, Enabling Efficient Resource Transfer in C++

From C++11, in addition to a copy constructor, we can have another special constructor called move constructor. The move constructor makes a class movable that enables efficient resource transfer. Let’s first quickly recap what a copy constructor does. We have a copy constructor in our mystring class. We created an object s1 with value “QnA … Continue reading “Move Constructor, Enabling Efficient Resource Transfer in C++”

Copy Constructor in C++

Copy constructor is a special constructor of a class that gets called when an object is initialized from another object. If we don’t create a copy constructor, the compiler will create one for us that will do member by member copy. This is called default constructor or default copy constructor. The default constructor will be … Continue reading “Copy Constructor in C++”

0
0
0
0
0
0