Tag: Pointer
C++11 Smart Pointer – Part 2: shared_ptr and Custom Deletor
In this article we will discuss how to use custom deleter with std::shared_ptr. When a shared_ptr object goes out of scope, its destructor is called. Inside its destructor it decrements the reference count by 1 and if new value of reference count is 0 then it deletes the associated raw pointer. Advertisements To delete the …
C++11 Smart Pointer – Part 2: shared_ptr and Custom DeletorRead More
C++11 Smart Pointer – Part 1: shared_ptr Tutorial and Examples
In this article we will discuss a smart pointer implementation provide by c++11 i.e. shared_ptr. What is std::shared_ptr<> ? shared_ptr is a kind of Smart Pointer class provided by c++11, that is smart enough to automatically delete the associated pointer when its not used anywhere. Thus helps us to completely remove the problem of memory leaks …
C++11 Smart Pointer – Part 1: shared_ptr Tutorial and ExamplesRead More
C++11 Smart Pointer – Part 3: shared_ptr vs Pointer
In this article we will compare C++11 Smart Pointer Implementation shared_ptr and a normal pointer. Let’s compare shared_ptr and raw pointer based on following aspects i.e. Advertisements Missing ++, – – and [] operator In comparison to a raw pointer, shared_ptr provides only these operators 1.) -> , * 2.)  Comparison Operators Frequently Asked: C++11 …
C++11 Smart Pointer – Part 3: shared_ptr vs PointerRead More
C++11 Smart Pointer – Part 4: Create shared_ptr objects carefully
We should create shared_ptr objects carefully. Checkout below two cases, [showads ad=inside_post] Advertisements 1.) Try not to use same raw pointer for creating more than one shared_ptr object because in that case different shared_ptr objects will not get to know that they are sharing the pointer with any other shared_ptr objects. How this can create …
C++11 Smart Pointer – Part 4: Create shared_ptr objects carefullyRead More
C++11 Smart Pointer – Part 5: shared_ptr, Binary trees and the problem of Cyclic References
Main advantage of shared_ptr is that it automatically releases the associated memory when not used any more. But if we don’t use shared_ptr carefully then this advantage can turn into a disadvantage. Let’s look how, Advertisements Suppose I have to design a binary tree and in it the node contains a pointer to left and …
Differences between a pointer and reference
Differences Between Pointer and Reference in C++ are as follows, 1.) Reference is a kind of const pointer that de-reference itself automatically. Yes, its similar to const pointer therefore once you have attached a reference to a variable or object then you cannot make it to point to someone else. Advertisements Now if you try to …
deleting this pointer and internal details of this pointer
In this article we will discuss what is exactly this pointer and what happens if we delete this pointer. what is this pointer? this pointer is a kind of pointer that can be accessed only inside non static member function and it points to the address of the object which has called the member function. …
deleting this pointer and internal details of this pointerRead More
this pointer in C++ | Tutorial & Example
What is this pointer ? this pointer is pointer that is accessible only inside the member functions of a class and points to the object who has called this member function. Let’s understand by an example, Rise of this pointer : Behind the scene Let’s understand this pointer in a step by step example, Create …
C++11 Smart Pointer – Part 6 : unique_ptr Tutorial and Examples
In this article we will discuss a Smart Pointer implementationstd::unique_ptr<> provided by c++11. what is std::unique_ptr ? unique_ptr<> is one of the Smart pointer implementation provided by c++11 to prevent memory leaks. A unique_ptr object wraps around a raw pointer and its responsible for its lifetime. When this object is destructed then in its destructor it deletes …
C++11 Smart Pointer – Part 6 : unique_ptr Tutorial and ExamplesRead More