Tag: Tutorial
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++ : Map Tutorial Part 1: Usage Detail with examples
In this article we see how & why to use std::map in c++. std::map Introduction std::map is an associative container that store elements in key-value pair. Advertisements Benefits of using std::map : It stores only unique keys and that too in sorted order based on its assigned sorting criteria. As keys are in sorted order …
C++ : Map Tutorial Part 1: Usage Detail with examplesRead More
C++ : Map Tutorial -Part 2: Map and External Sorting Criteria / Comparator
In this article we will discuss how to use external sorting criteria for keys in std::map and points that we need to take care with external sorting criteria. Default sorting criteria for keys in std::map is operator “<” i.e. std::less<T>. So, while creating std::map if we don’t specify the external sorting criteria then default criteria …
C++ : Map Tutorial -Part 2: Map and External Sorting Criteria / ComparatorRead More
C++ : Map Tutorial Part 3: Using User defined class objects as keys in std::map
In this article we will discuss how to use User defined classes as key in std::map. By default std::map uses “operator <” as sorting criteria for keys. For default data types like int and std::string etc, operator < is available by default but for User defined classes operator < is not available by default. Advertisements …
C++ : Map Tutorial Part 3: Using User defined class objects as keys in std::mapRead More
C++ Set example and Tutorial – Part 1
In this article we will discuss how to use std::set with default sorting criteria. std::set – Introduction std::set is an associative container and header that need to be include for it is,#include<set> Advertisements Benefits and Features of std::set: It’s doesn’t allow duplicate elements i.e. it only contains unique elements. Std::set can contain element of any …
c++ std::set example and tutorial with external Sorting criteria | Comparator
In this article we will see how to use external Sorting Criteria i.e. Comparator in std::set. Suppose our class is Message that contains three properties i.e. • Member content • Sending User Name • Receiving User Name Advertisements Requirement: we want to keep only single message sent by each user i.e. only one sent message …
c++ std::set example and tutorial with external Sorting criteria | ComparatorRead More
C++ std::set example and tutorial with user defined classes
In this article we will see how to use std::set with user defined classes. If you want to use std::set with user defined classes and use default sorting criteria then overload operator < in the class. Advertisements For example, Suppose our class is Message that contains three properties i.e. • Member content • Sending User …
C++ std::set example and tutorial with user defined classesRead More
std::for_each Tutorial : Usage Details with Examples
The std::for_each() algorithm allows us to iterate over a given range of elements and perform operations over them.When to use std::for_each() ? Whenever you are iterating over the elements in a array or in a container and performing some different opeartions over them like accessing, modifying etc. Although you can achieve the same by typing …
std::for_each Tutorial : Usage Details with ExamplesRead More
C++11 Lambda Function : Example & Tutorial
In this article we will discuss, what is a C++11 Lambda Functions, how to use Lambda Functions as Callbacks. What is a Lambda Function? Lambda functions are a kind of anonymous functions in C++. These are mainly used as callbacks in C++. Lambda function is like a normal function i.e. Advertisements You can pass arguments to …
C++ std::list Tutorial, Example and Usage Details
In this article we will discuss std::list usage details. What is std::list ? std::list is sequential STL container that is internally implemented as doubly linked list. i.e. every element in the list is stored at a seperate memory location i.e. called node and it also contains a pointer to the previous and next node. Advertisements …