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

Create a album using multi-dimensional arrays, Create a Document that show ...

Create a Document that show information about albums. First create a paragraph or two about the purpose of the page and your interests in music: genres, styles, etc. Next have a

Described access privileges in c++? what is the default , A: In C++ the acc...

A: In C++ the access privileges are public, private and protected. The default access level assigned to members of a class is private. Private members of any class are accessible o

Area, write a program to find the area under the curve y=f(x) between x=a &...

write a program to find the area under the curve y=f(x) between x=a & x=b

Program that computes square matrix multiplication, Goal: Design a progr...

Goal: Design a program that computes square matrix multiplication on GPU using CUDA. Write the code in C. In particular, your implementation should obey the following requiremen

Example of switch case statement, #include #include #include void* m...

#include #include #include void* memorycopy (void *des, const void *src, size_t count) {   size_t n = (count + 7) / 8;   char* destination = (char *) des;   char* source =

Matrices, write a c program that multiplies 3 martices

write a c program that multiplies 3 martices

Explain constructors, Constructors By definition, a constructor functio...

Constructors By definition, a constructor function of some class is a member function that automatically gets implemented whenever an instance of the class to which the constru

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