But operator overloading makes class look ugly; isn''t it , C/C++ Programming

Assignment Help:

Q: But operator overloading makes class look ugly; isn't it assumed to make my code clearer?

A: Operator overloading makes life simpler for the users of a class, not for developer of the class!

Assume the following example.

class Array {

public:

int& operator[] (unsigned i); // Some people don't like this syntax

...

};

inline

int& Array::operator[] (unsigned i) // Some people don't like this syntax

{

...

}

Some programmer doesn't like the keyword operator or the somewhat humorous syntax which goes with it in the body of the class itself. However the operator overloading syntax isn't imagined to make life simpler for the developer of a class. It's imagined to make life simpler for the users of the class:

int main()

{

Array a;

a[3] = 4; // User code should be obvious and easy to understand...

...

}

Remember: in a reuse-oriented world, usually there will be many people, who employ your class, although there is only one person who builds it (yourself); thus you should do things that favor the several instead of the few.

 


Related Discussions:- But operator overloading makes class look ugly; isn''t it

Virtual memory implementation, I need help with virtual memory manager impl...

I need help with virtual memory manager implementation in C

Write short note on classes in c++, Introduction to Classes Object-orie...

Introduction to Classes Object-oriented programming (OOP) is a conceptual approach to design programs. It can be executed in many languages, whether they directly support OOP c

Example of array, In this lab, please complete a given program to perform t...

In this lab, please complete a given program to perform the following tasks: 1. Allocate a 10 by 5 2D byte array dynamically. The way of allocation must be consistent with pag

Define auto pointer?, A: The simplest instance of a smart pointer is auto_p...

A: The simplest instance of a smart pointer is auto_ptr that is included in the standard C++ library. Auto Pointer only takes care of Memory leak & does nothing regarding dangling

Program of cascading, Program of cascading: class vector{          ...

Program of cascading: class vector{                 private :                 int v[3];                   public:                 friend istream & operator >> (

Luminous Jewels - The Polishing Game, Damjibhai and Shamjibhai are two jewe...

Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed

Control structures in cpp, Control structures The control structures app...

Control structures The control structures appear in both structured programming languages as well as object oriented programming languages.  The three constructs used are: i)

Recursion, write a cprogram to calculate fraction through recursion

write a cprogram to calculate fraction through recursion

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd