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

In binary mode how can i open a stream?, A: Use std::ios::binary. Some o...

A: Use std::ios::binary. Some operating systems differentiate among text and binary modes. In text mode, end-of-line sequences and perhaps other things are translated; in binary

MINIMUM SHELVES, Write a program to find minimum number of shelves

Write a program to find minimum number of shelves

Last ant on rod, You are given a collection of words, say as in a dictionar...

You are given a collection of words, say as in a dictionary. You can represent it in the following compressed form: the first word will be followed by a sequence of a pair of numbe

What does odbc do in context with php, What does ODBC do in context with PH...

What does ODBC do in context with PHP? PHP supports many databases such as dBase, Microsoft SQL Server, Oracle, etc. however, it also supports databases such as filePro, FrontB

#psuedocode, Create a pseudocode in getting Calendar Quarter. The program s...

Create a pseudocode in getting Calendar Quarter. The program should identify which quarter falls the given date. Note: Consider the date format DDMMYYYY.

Program of binary tree, Program of Binary tree: Btree::Btree(int O) : ...

Program of Binary tree: Btree::Btree(int O) : itemsInContainer(0) {     finishInit(O); }   Btree::~Btree(void) {     if( root != 0 )         delete roo

Arrays, how to declare multi dimensional array

how to declare multi dimensional array

#padovan string in c , #padovan string in java   program in java /...

#padovan string in java   program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring; public class PadovanStrin

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

Produce data from fixed ocr areas scanned, Produce data from fixed OCR area...

Produce data from fixed OCR areas scanned. Project Description: Project is to design software which can use character recognition only on certain areas of scanned puff's/ jpe

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