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

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.

 

Posted Date: 3/20/2013 3:44:51 AM | Location : United States







Related Discussions:- But operator overloading makes class look ugly; isn''t it , Assignment Help, Ask Question on But operator overloading makes class look ugly; isn''t it , Get Answer, Expert's Help, But operator overloading makes class look ugly; isn''t it Discussions

Write discussion on But operator overloading makes class look ugly; isn''t it
Your posts are moderated
Related Questions
Define the Float Data Type of c Language? The float is used to define floating point numbers. The Floating point numbers are stored in 32 bits with 6 digits of precision. Eg

write short notes about void pointers

Need help in network programming in C++ project. How much you charge?

Four cells, each with an internal resistance of 0.40 ? and an e.m.f. of 2.5 V are connected in series to a load of 38.40 ?. (a) Verify the current flowing in the circuit and t


how to avoid duplicates strings in an array

for object, malloc allocates memory in heap however doesn't invoke object's constructor to initialize the object. new allocates memory & also invokes constructor to initialize the

Develop G-code generating software Project Description: I'm presently using Slicer on a polymer jetting 3d printer. The toolpaths were thought out for FDM printers and thus a

when you allocate memory with new[], you ought to free the memory via delete[]. While you allocate memory along 'new', then use 'delete' with no the brackets. You employ new[] to a