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
At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

A: Here are a few of the many instance of operator overloading: myString + yourString may concatenate two std::string objects myDate++ may increment a Date object a * b may m

Overloading a method (or function) in C++ is the ability for functions of the similar name to be defined as long as these methods have dissimilar signatures (different set of param

Compiler Design - Limit In The Method Instructions

Write C code for a program that implements a digital clock (HH:MM:SS). The clock includes a two-digit hour indicator HH (00-23), a two-digit minute indicator MM (00-59), and a t

A: The simplest way is to use a stringstream: #include #include #include using namespace std; string itos(int i) // convert int to string { stringstream s;

A skilled programmer is required to build a standalone module to extract, parse and store in database tables, word count data from web pages and RSS feeds. The module will take

Array of Objects: The objects can be declared just like a structure or even a primary data type.  Array of objects may be required to work with large set of data.   When the da

# c pragram TO count the number of occurances of the string in nth padovan''s string program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : pa

(a) Verify the values of the resistors with the following colour coding: (i) red-red-orange-silver (ii) orange-orange-black-blue-green (b) What is the value of a resistor