C++ 11 feature: dynamic_cast with RTTI

“dynamic_cast” is new concept in C++ 11. dynamic_cast is used at runtime to check the correctness of down casting. As it checks the correctness at runtime, it is slower than “static_cast”. “dynamic_cast” is used in handling polymorphism. “dynamic_cast” will return the object if the cast is correct else it will return NULL. Note: There should […]

C++ 11 feature: const_cast

“const_cast” is new concept in C++ 11. const_cast is used to remove the constantness from references and pointers. I agree we used const pointer so to avoid un-necessary data modification. But there will be some instances where you need to modify the const data. In such situation “const_cast” will be useful. Syntax of const_cast cast: […]

C++ 11 feature: static_cast

Casting is a new feature in C++. Below are the different types of csating available: 1. Static Cast 2. Dynamic Cast 3. Const Cast 4. Reinterpret Cast static_cast in smart pointers: Points on Static cast: 1. static_cast is used for compile time checking. 2. static_cast can easily be searched in C++, thus making easily readable […]

C++ 11 feature: typealias

“typealias” is a new feature introduced in C++ 11. It is the replacement of typedef. “using” is the keyword used in typealias. typealias is used to give an alternate name for already exsisting data type. We shall see how to define using typealias and also using typedef. If you want to defined “unsigned long” to […]

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 […]