Relational Operators Overloading in C++
In this chapter we shall see how to overload relational operators [<, >, <=, >=, ==]. #include <iostream> // for more tutorials check www.prodevelopertutorial.com using namespace std; class MyClass { private: int num_1; public: MyClass(int a): num_1(a){ } friend void operator < (MyClass &obj1, MyClass &obj2); friend void operator > (MyClass &obj1, MyClass &obj2); friend […]
Binary operator overloading in C++
In this chapter we shall see how to overload binary operators [+, -, *, /]. Example: #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){ } friend MyClass operator + (MyClass &obj1, MyClass &obj2); friend MyClass operator – […]
Overloading of stream insertion “<>” operator in C++
In this chapter we shall see how to overload stream insertion and stream extraction operator. Stream Insertion “<<” operator is used for output. Stream Extraction “>>” operator is used for input. cout is an object of Ostream Class. cin is an object of Istream Class. Few important points on stream insertion and extraction operator We […]
C++ Overloading Unary Increment (++) and Decrement Operator (–)
In this chapter we shall see: 1. Overloading prefix increment operator without return type 2. Overloading prefix increment operator with return type 3. Overloading Postfix increment operator 4. Overloading prefix and postfix decrement operator 1. Overloading prefix increment operator without return type Consider the example below; #include <iostream> using namespace std; class MyClass { private: […]
C++ Operator Overloading tutorial
As we saw in previous chapters, we are able to perform function overloading. Similarly we can also overload operators “+, -, =, *” and we call this concept as operator overloading. Why do we need operator overloading? Consider a simple example: Generally we use arithmetic addition operator to add integers. But there comes a case […]
C++ 11 feature: C++ Multithreading Tutorial: std::try_lock
1. try_lock is used to lock multiple mutex. 2. try_lock is used to lock the objects by using try_lock member functions. 3. It is a non blocking call 4. It tries to lock all the objects in the given order 5. On success it will return -1 otherwise it will return 0-based mutex index number […]
C++ 11 feature: C++ Multithreading Tutorial: std::lock
std::lock is used to lock multiple mutex at the same time. Syntax: styntax: std::lock(m1, m2, m3, m4); It will be able to lock all the objects in a non deadlock way by using deadlock avoidance algorithm. It will make series of lock, try_lock, and unlock to achieve this. It is a blocking call. The order […]
C++ 11 feature: C++ Multithreading Tutorial: std::async and std::future
In the previous chapter we studied about promise and future. In this chapter we shall see how to achieve the same using “async” and “future”. “async” is present in namespace std. “std::scync” is used to get asynchronous execution of the tasks. It means, you start a thread, and comeback to the calling function start executing […]
C++ 11 feature: C++ Multithreading Tutorial: std::promise And std::future
First we shall see some points related to Promise and Future. Promise: It is an asynchronous provider. std:async is another asynchronous provider. That we shall see in next chapter. Future: It is an asynchronous return object. It is used to get a value from promise. It will wait for notification from promise. In general: A […]
C++ 11 feature: C++ Multithreading Tutorial: Conditional Variables in C++ threading
Condition Variable is a class in C++ A conditional variable is used to block and object until it is “notified” to makeup. To use conditional variables, we need to use below header: #include <condition_variable> // std::condition_variable Conditional variable uses unique_lock to lock a thread when one of its wait functions is called. Then that thread […]