answersLogoWhite

0


Best Answer

When you overload the -- and ++ operators in C++, if you want the pre version, aka --var, simply declare the function without an argument; whereas if you want the post version, aka var--, simply declare the function with an argument of type int.

class abc {

public:

abc& operator++(); // pre-increment form

abc& operator++(int); // post-increment form

...

};

abc::operator++() {

... pre increment stuff

return *this;

}

abc::operator++(int) {

... post increment stuff

return *this;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How the predecrementer and postdecrementer are taken care of while declaring operator overloading?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is it possible to do operator overloading in c?

No. Operator and/or function overloading is only a C++ thing.


Operator overloading is possible in java or not?

Java does not support opperator overloading, so the answer to your question is: none.


C coding for operator overloading?

C does not support operator overloading. If you mean C++ operator overloading, it depends on exactly what you wanted to do. If you wanted to '+' to strings, then you could write: string operator+(string a, string b) { // do something }


When an operator works on various type of operands is called?

operator overloading


How operator overloading differ from function overloading?

Function overloading is multiple definition with different signatures(the parameters should be different) for the same function. The parameter list have to be different in each definition. The compiler will not accept if the return type alone is changed. Operator overloading is defining a function for a particular operator. The operator loading function can not be overloaded through function overloading.


Is it possible to use operator overriding in java?

short answer: no longer answer: 10 seconds on google would get you to http://java.sun.com/docs/white/langenv/Simple.doc2.html There are no means provided by which programmers can overload the standard arithmetic operators. Once again, the effects of operator overloading can be just as easily achieved by declaring a class, appropriate instance variables, and appropriate methods to manipulate those variables. Eliminating operator overloading leads to great simplification of code.


How can you differentiate overloading of pre-fix and post-fix increment operator?

The prefix increment operator is overloaded as operator++() while the postfix increment operator is overloaded as operator++(int).


What is operator overloading?

I think you mean operation overlord??? It is the American, Canadian and British offensive on Europe in World War 2. They landed in Normandy on 6th June 1944 (Commonly called D-Day, Day of Days or Deliverance Day) and progressed throughout France liberating Paris on the 25th August. This allowed the allies a foothold in Europe.


What are the disadvantage of operator overloading?

The only disadvantage of operator overloading is when it is used non-intuitively. All operators must behave with predictable results, thus it makes no sense to implement the plus (+) operator so that it behaves like a subtract (-) operator, or a multiply (*) operator, or indeed anything other than the intuitive sum of two objects.


What is an operator overloading in C?

one function but multiple behaviours depending on the parameters


How do you find largest of two object using operator overloading in c?

I will not use operator overloading in C# to do anything. Operator overloading may lead to one operator has more than 1 semantic meaning. For example, we know 1 + 2 yields 3, and "1" + 2 yields "12". I do not like this overloading of the operator + being used for addition in Number hierarchy, while as the concatenation in strings. That is, one operator (+) has 2 significant semantics.And the question "find largest of two object" is too vague - what do you mean "largest"? and object? We know apple and orange are 2 objects, but how do you compare them, and find the largest one?????? (size, price or what???)


What are the restriction that are applied to operator overloading?

Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.