answersLogoWhite

0


Best Answer

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???)

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you find largest of two object using operator overloading in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


How operator overloading is useful in class based programming?

The concept of Operator Overloading is similar to Method Overloading, in that the meaning of a given operator symbol changes according to the context it is being used in. That is, the semantics of the operator symbol are flexible, rather than fixed.The idea behind Operator Overloading is to take a common symbol, and adjust it's meaning to something logical for contexts other than what it was originally restricted to.The arithmetic operators ( + - * / ) are good examples. Using Operator Overloading, I could define that 'SomeArray + SomeValue' means that I should add SomeValue to the end of the array SomeArray.In general, Operator Overloading is what is called 'syntactic sugar' - it makes things more readable. For instance, the equivalent way to do the above example via method calls would be: SomeArray.addToEnd(SomeValue)The major problem with Operator Overloading is that it depends on people having the exact same interpretation of what an operator would mean in the new context, which is difficult to assure. Going back to the above example, there is some ambiguity as to where 'SomeArray + SomeValue' would mean to add in SomeValue - should SomeValue be added to the start of the array, or the end of the array? The answer is not obvious, and one would have to go look through the overload definition. While this confusion is also possible with methods, properly named methods (i.e. using addToEnd() rather than just add() ) helps avoid this entirely.For this reason, Java does not support user-defined Operator Overloading. Java does support certain operator overloading in narrow contexts, but only those defined by the language itself. That is, the '+' sign is overloaded to allow for string concatenation. However, the designer of Java (James Gosling) decided that his preference was to avoid Operator Overloading completely due to his perception of a "clean" language.


Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.


Why operator overloading is not there in java?

== == === === === === === === Some Body told me that operator overloading is not there because it violates the transparency of java.since there is no hiding of information in java it does support op overloading === === === === === === Pranab Kumar Rana Software Engineer..... === === === ===


What is the importance of overloading and overriding?

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.

Related questions

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.


Why ostream operators not overloaded using member functions?

Consider the following line: cout<<obj; where obj is the object of Demo class. In this case we are overloading "<<" operator. But overloading the binary operator using member function, the left hand operand should be the object of relevant class. Here in this case left hand side operand is not the object of Demo class. It is object of ostream class. Hence we cant overload ostream operators using member function. But we can overload these type of operators using friend functions. Thanks, Prof. D. H. Ingole


How operator overloading is useful in class based programming?

The concept of Operator Overloading is similar to Method Overloading, in that the meaning of a given operator symbol changes according to the context it is being used in. That is, the semantics of the operator symbol are flexible, rather than fixed.The idea behind Operator Overloading is to take a common symbol, and adjust it's meaning to something logical for contexts other than what it was originally restricted to.The arithmetic operators ( + - * / ) are good examples. Using Operator Overloading, I could define that 'SomeArray + SomeValue' means that I should add SomeValue to the end of the array SomeArray.In general, Operator Overloading is what is called 'syntactic sugar' - it makes things more readable. For instance, the equivalent way to do the above example via method calls would be: SomeArray.addToEnd(SomeValue)The major problem with Operator Overloading is that it depends on people having the exact same interpretation of what an operator would mean in the new context, which is difficult to assure. Going back to the above example, there is some ambiguity as to where 'SomeArray + SomeValue' would mean to add in SomeValue - should SomeValue be added to the start of the array, or the end of the array? The answer is not obvious, and one would have to go look through the overload definition. While this confusion is also possible with methods, properly named methods (i.e. using addToEnd() rather than just add() ) helps avoid this entirely.For this reason, Java does not support user-defined Operator Overloading. Java does support certain operator overloading in narrow contexts, but only those defined by the language itself. That is, the '+' sign is overloaded to allow for string concatenation. However, the designer of Java (James Gosling) decided that his preference was to avoid Operator Overloading completely due to his perception of a "clean" language.


Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.


Which operator require to call c function using object name?

The operator required to call c function using object name is function object. Other operator names that deal with objects are structure dereference, structure reference, and indirection


Why operator overloading is not there in java?

== == === === === === === === Some Body told me that operator overloading is not there because it violates the transparency of java.since there is no hiding of information in java it does support op overloading === === === === === === Pranab Kumar Rana Software Engineer..... === === === ===


How can you download c compiler?

write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)


What is the importance of overloading and overriding?

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.


Why is it necessary to overload an operator?

The assignment is done explicit without internal operation. Subject to the programming language, explicit assignment operators are needed wherever implicit ones are insufficient. Implicit assignment is typically implemented as a flat copy, while explicit overloading of the assignment operator allows for any other suitable behavior. Consider this example in pseudocode similar to C++: class Demo { int* valuepointer; ... }; Demo a, b; ... b = a; Assigning a to b using implicit assignment means that a.valuepointer and b.valuepointer share the same value. Both a and b can change the pointed-to value, and the either will "see" the change. This is the required behavior in some cases, but often, you'd want to explicitly assign a to b such that each has its own pointer, accessing different copies of the value. This behavior would require an explicit assignment operator (or copy constructor).


What is the use of new operator?

A new operater is used to allocating a memory space for a particular object.


How do you invoke method by using object of the class?

If you have and object with method described within its class you can use dot access operator, for instance:myObject.DoSomething();


Why to take two arguments in binary operator overloading using friend function?

Binary operators require two operands (l-value and r-value) and therefore require two arguments when overloading via external functions. When overloading class member operators, the l-value is the class instance itself (the implicit this pointer), therefore only the r-value need be given as an argument.