Tag: in
How to use vector efficiently in C++?
We can use vector efficiently by taking care of following points, 1.) Vector will be more efficient if elements are inserted or removed from the back-end only. Advertisements As, vector internally stores all the elements in consecutive memory location. Therefore, if an element is added in middle, then vector right shifts all the right side …
Designing Callbacks in C++ – Part 1: Function Pointers
In this article we will discuss what is a callback and what types of callbacks we can have in C++ and how to Design Callbacks as function pointers. Now what is a callback? Advertisements Callback is a function that we pass to another APIs as argument while calling them. Now these APIs are expected to …
Designing Callbacks in C++ – Part 1: Function PointersRead More
Designing Callbacks in C++ – Part 2: Function Objects & Functors
In this article we will discuss, what is a Function Object, why do we need function objects and how to use function objects as Callbacks. What is a Function Objects: Advertisements A Function Object / Functor is a kind of Callback with State. In a Programmer’s terminology, Frequently Asked: Designing Callbacks in C++ – Part …
Designing Callbacks in C++ – Part 2: Function Objects & FunctorsRead More
What is a Memory Leak in C++ ?
In this article we will discuss what is Memory Leak C++ and why its harmful for applications. Memory Leak Advertisements Memory leak in is a kind of Bug that kills your application slowly by first making it slow and then eventually crashing it. How Does Memory Leak happens: Frequently Asked: What is a Memory Leak …
Handling Out Of Memory Errors in Code
In this article we will discuss how to Handle Out of Memory errors in a C++ Application. Each process has a limited free storage or heap associated with it for dynamic memory allocation. If application consumes all the memory from heap then process will crash with out of memory error. Advertisements Check out following example, …
How to trim strings in C++ using Boost String Algorithm Library
In this tutorial we will discuss how to use trim algorithms from C++ Boost String Algorithm Library. Let’s learn them step by step, Boost String algorithm library provides different algorithms for string trimmings. Let’s first discuss the simple one i.e, What if we want to trim the string of white spaces from left side or …
How to trim strings in C++ using Boost String Algorithm LibraryRead More
Creating a Matrix using 2D vector in C++ – Vector of Vectors
In this article will discuss how to create 2D Matrix using vector of vectors in c++. Requirement Advertisements Represent a 2D Matrix using vector in C++ i.e. 1 , 1 , 1 , 1 1 , 1 , 1 , 1 1 , 1 , 1 , 1 1 , 1 , 1 , 1 …
Creating a Matrix using 2D vector in C++ – Vector of VectorsRead More
Different Ways to Initialize a vector in C++
In this article we will discuss different ways to initialize a std::vector in C++. Initializing std::vector elements with same value std::vector<int> vec_1(5, 10); It will create a vector of 5 element and initialize  each element is initialized to 10. Advertisements Initializing std::vector elements with passed argument list std::vector<int> vec_2 = {10,20,30,40,50}; It will create a vector of 5 …
Designing a Board Game (Mastermind) in C++ using MVC, State and Observer Design Patterns
Let’s Design a Console Based Board Game in C++. With this Design you can learn MVC, Observer and State Design Pattern. Moreover, with the same design you can also implement any other Game Like Battleship etc. Advertisements In this we will build Console Based Version of MasterMind Game. Complete Code for this is available at, Frequently …
Designing a Board Game (Mastermind) in C++ using MVC, State and Observer Design PatternsRead More
How to pass variable arguments in a function
In this article we will discuss how to pass variable number of arguments in a function. Requirement: Advertisements Suppose I want to create a function that take variable number of arguments and use them to perform some task. For example, Create a function that will return the sum of all the passed arguments i.e. Frequently …