Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:22:49+00:00 2026-05-26T11:22:49+00:00

I’ve been going through Deitel’s C++ Fundamentals and mr. Deitel accented on overloading standard

  • 0

I’ve been going through Deitel’s C++ Fundamentals and mr. Deitel accented on overloading standard operators to provide standard functionality to custom classes and their members. What I mean is for example instead of cout << object.memberFunction(); I can simply say cout << object;

This technique does allow chaining and quicker typing, but it requires operator overloading implementation and even thou I am still a newb, I fell like the code actually gets less readable, especially if there are many class members you have to remember which ones are operators overloaded for and so on. Without overloaded operators code is much more readable plus you save the overloading code.

So my question is whether I should take the time to learn operator overloading? I am new to C++ and answers from people with more practice and experience is welcome. Will the benefits of operator overloading outweigh the efforts to implement it and the reduced code readability?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:22:49+00:00Added an answer on May 26, 2026 at 11:22 am

    I’m tempted to say that there isn’t anything to learn about operator
    overloading; overloaded operators are just funny named functions. What
    you do have to learn is when overloading is appropriate, and when it is
    not. Certain idioms are more or less standard: numeric types overload
    the appropriate numeric operators (+, etc.), smart pointers overload
    the pointer ops (* and ->), container types which support indexation
    overload [], and functional objects overload (). And that’s about
    it for the special cases. And while it’s arguably an abuse, if you
    define an iterator, you’ll want it to support the standard iterator
    idiom (which means ++, *, -> and ==/!=).

    In addition to these, there are three operators which will be overloaded
    for many different types of classes: assignment is done using =, and
    insertion into and extraction from streams is done using << and >>.
    If you want your class to support any of these, you should use the
    overload. And comparison uses == and != for equality, and <,
    <=, > and >= for inequality. But don’t overload for inequality
    unless it is semantically significant. It’s better to provide an
    explicit ordering function for use with std::map and std::set than
    to mislead readers into thinking you’ve defined as semantically
    significant ordering. You might want to specialize std::less on your
    class in this case; < won’t work, or will have inappropriate semantics
    for use as a key, but std::less will define an arbitrary ordering
    which will. And while it’s not operator overloading, if the type is to
    be used as a key in associative containers, you’ll also want to provide
    a function hash_code and an instantiation of struct std::hash.

    In many cases, it’s best to define the overload in terms of some more
    global function: for example: I use compare (returning an int less
    than, equal to, or greater than 0), for inequality; I’ll define a public
    function compare in the class, and then derive from something like:

    template<typename T>
    struct ComparisonOperators
    {
        friend bool operator==( T const& lhs, T const& rhs )
        {
            return lhs.compare() < 0;
        }
        //  ...
        //  The same for the other five operators.
    };
    

    (My implementation is actually somewhat more complex, as it uses
    metaprogramming to use isEqual for == and != if the class provides
    it.)

    I use a similar techique for the binary arithmetic operators, defining
    + in terms of +=, etc. I also use it for IO, defining << in terms
    of print and >> in terms of parse; this is mainly useful when the
    operators need to be polymorphic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.