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, …
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; …
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 …
In C++ there is a concept of Dynamic Memory Allocation. The concept of allocating memory during run time is called as Dynamic Memory Allocation. Here the memory allocated in Heap segment. You can use C style “malloc ()” and “free ()” functions, but C++ provides “new” …
An exception is an error condition that occurs during run time. Generally without exception handling, the program will crash when there is an exception. We place the code where the exception might occur and we handle that exception without crashing the program. C++ provides 3 types …