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
The voltage at the terminals of a battery is 52V when no load is linked and 48.8V when a load taking 80A is connected. Find the internal resistance of the battery. What wou

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

Develop a .NET wrapper for a C++ Dll Project Description: We have a classic VC++ Dll that requires a .NET wrapper built by you. Use latest Visual Studio and .Net framework sh

Write a program to calculate the total resistance of a series or parallel circuit. The maximum number of resistors is two.   We need to decide whether the user wants the to

WHAT IS CGI?

In this worksheet you are asked to write three classes in C++: Lecture class, Course class and University class. The classes relate to each other in the way that a Course has many

Problem: (a) Using a class hierarchy of your own choosing, with at least TWO subclass levels, show (i) the use of abstract and concrete forms of Java class and method in you

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

how do you declare an integer variable

Develop Diablo 2 LOD 1.13d Dupe Method for Closed Battle.net This hack is for diablo 2 lord of destruction The program must work on all realms, all cores, all ladders (4x rea