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++”

std::move – Efficient Resource Transfer from One Object to Another

C++11 introduced this std::move() to enable efficient resource transfer from one object to another. Let’s first understand what efficient resource transfer means. We created a string object, s1, with value, ‘QnA Plus‘. We can imagine what might have happened during this s1 object creation. One constructor would have been called that allocated memory how hold … Continue reading “std::move – Efficient Resource Transfer from One Object to Another”

Inline Function in C++

When a normal function is called, the execution control goes into the called function and returns back to the caller upon completion of the called function. But in C++, if a function is marked as ‘inline‘, the compiler substitutes the code within the function definition for every instance of a function call. In case of … Continue reading “Inline Function in C++”

0
0
0
0
0
0