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

Debug the following program to calculate N! #include using namespace std; main() {             int N, factorial=1;             cout             cin >> N;

Problem : (a) What do you understand by the term ‘constructor' in Java? Explain with an appropriate example. (b) Describe the differences between an object and a class usi

What are the debugging methods you employ while came across a problem? A: Debugging with tools such as: 1.      DBG, GDB ,Forte, Visual Studio. 2.      Using tusc to trace

Write a c++ program to find the sum of 0.123 ??103 and 0.456 ??102 and write the result in three significant digits

progarm in c for area under curve   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; int numtraps;

Problem : Compiler Design - Limit the methods Rahul is a newbie to the programming and while learning the programming language he came to know the following rules: ·

Pupils' heights The health visitor at a school is going to measure the heights of all pupils. For each class she makes a statistics giving the number of pupils of each height and

The Special Pointer 'this' When various instances of a class come into existence, it naturally follows that each instance has its own copy of member variables. If this were not

i am using otlv4 for database connecttvity, while i try to get all tables list from current database using query "$SQLTables" no output is displayed though programe compiles coretl