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”
Category: C++
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++”
Template Class in C++
Like template function, we can create a template class that will operate on generic types. That means that we can have a single class that will work for, say, int, double, string etc. We don’t need to have separate class from each data type. In this example, we have a template class, LinkedList. We can … Continue reading “Template Class in C++”
Template Function in C++
In C++, we can write a function to operate on generic types. If we want to have the same function for different data types like, int, double, string, etc., we can have only one template function instead of having different functions with different names or multiple overloaded functions. In this example, we have a template … Continue reading “Template Function in C++”
Function Overriding in C++
In inheritance, the derived class inherits all the functions from the base class with same behavior. That means that an inherited function will behave in the exact same way in both derived and base classes. But we can redefine the behavior of a particular inherited function in derived class. The feature is called function overriding. … Continue reading “Function Overriding in C++”