There are various types of operators in C++. In our recent posts, we have covered overloading of a bunch of arithmetic operators. There are some arithmetic operators which perform compound functions. It means they handle more than one mathematical function at a time. The Plus Equal or Addition Assignment Operator or plus equals to operator (+=) is one of these. As the name implies, it adds and assigns the value to the variable at the same time. The plus equal operator is quite often used in programming. We shall learn how to overload it.
Posts Tagged ‘operator overlaoding’
C supports a number of arithmetic and logical operators. Post and Pre Increment operators are one of these arithmetic operators. These incremental operators add up one to existing value of the variable.The difference between post increment and pre increment is obvious from their name: post increment is placed after the variable and pre increment is placed before the variable. In principle, there is a slight difference in their behavior which I shall explain to you in this article.
The extraction operator is used to take input directly in objects. In Object Oriented Programming, we want everything to be as simple and close to built in data types as is possible. The concept of overloading various operators is one facet of this need. For input and output, we especially want ease and smooth syntax to flow throughout the program.We saw how to overload insertion operator for taking output in our program. This time we shall see how to overload the extraction operator (>>) for taking input directly in an object.
We have been discussing rather overloading various operators in the object oriented paradigm in the past. Overloading operators in our class is solely for our own benefit and effectiveness of the program. It saves us from writing lengthy complicated code over and over again. When we work with objects and there is an Array inside that object, we would certainly want to output it time and again. Instead of making a loop for that every time, we overload the insertion operator (<<) once and for all which is used to cout the data on our screen. Let us see how to do that.
Assignment is not a simple task in object oriented programming. It may take you a day to trace out an error that is happening because of incorrect assignment, let alone fix it. In a post before, I dealt with some issues while assigning one object to another. Still there are some issues associated with it. So I shall write a code and explain to you its errors. Kindly Follow this piece of Code.