C++ 11 feature: auto and decltype
auto and decltype are the 2 new keywords that have been added in C++ 11. In this chapter we shall see how to use both of them. auto: auto keyword is used to automatically infer the type of the variable. decltype: decltype let us to extract the type of the variable and assign it to […]
C++ 11 feature: Delegating constructor
Delegating constructor is a new concept in C++ 11. Why we need delegating constructor? 1. Delegating constructor is used to prevent code duplication. 2. It is the only way to delegate the initialization list 3. Consider the code below: #include <iostream> //for more C++ tutorial visit www.ProDeveloperTutorial.com using namespace std; class MyClass { int a; […]
C++ 11 feature: constexpr
“constexpr” is a new concept in C++ 11. In this chapter we shall have a look at “constexpr” topic. “constexpr” are used in the scenario, where there is a possibility to evaluate the value of the function or variable at compile time. “constexpr” is the keyword used to create a constant expression. Constant expression can […]
C++ 11 feature: nullptr
“nullpt” is a new concept that has been introduced in C++ 11. Earlier to C++ 11, NULL has been defined as: #define NULL 0 But after C++ 11, NULL has been defined as #define NULL nullptr “nullptr” is defined in #include <cstddef> header file. It means earlier to C++ 11, the NULL will be converted […]
C++ 11 Smart pointers : weak_ptr tutorial and example
unique_ptr is a smart pointer available in C++ 11. Weak pointer is used along with shared pointers. You cannot create a standalone unique pointers. Example of weak pointer: #include<iostream> #include <memory> //for more C++ tutorial visit www.ProDeveloperTutorial.com using namespace std; class MyClass { public: MyClass() { } ~MyClass() { } }; int main() { shared_ptr<MyClass> […]
C++ 11 Smart pointers : unique_ptr tutorial and example
unique_ptr is a smart pointer available in C++ 11. Below are the points that we shall see in unique_ptr. 1. Points on unique_ptr 2. Syntax for creating an unique pointer: 3. How to create an objet using make_unique? 4. Example 1 5. Example 2 6. How to use make_unique()? Points on unique_ptr: 1. unique_ptr as […]
C++ 11 Smart pointers : shared_ptr tutorial and example
Smart Pointers are available from C++ 11. Smart pointers are used to make sure that the object gets deleted if it is no longer used. In this chapter we shall learn about “shared_ptr” concept. We shall learn about below topics: 1. Introduction 2. How to create a shared_ptr object? 3. How to create an object […]
C++ 11 feature rvalue reference and move constructor
In this chapter we shall learn about: 1. what are lvalue and rvalue. 2. What are reference variables? 3. what are rvalue reference. 4. Example for rvalue reference. 5. Move constructor What are lvalue and rvalue? The value on the left side of assignment operator is lvalue. The value on the right side of assignment […]
Overloading new and delete operator in C++
We can overload new and delete operator in C++. There are 2 ways to overload. 1. Locally Overloading new and delete operator 2. Globally Overloading new and delete operator Syntax for new operator overload: void* operator new(size_t size); 1. Locally Overloading new and delete operator #include <iostream> // for more tutorials check www.prodevelopertutorial.com using namespace […]
Assignment Operators Overloading in C++
In this tutorial we shall see how to overload assignment operator “=”. #include <iostream> // for more tutorials check www.prodevelopertutorial.com using namespace std; class MyClass { private: int num_1; int num_2; public: MyClass(int a, int b): num_1(a), num_2(b){ } void operator = (const MyClass &obj ) { num_1 = obj.num_1; num_2 = obj.num_2; } void […]