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

  • Home
  • SEARCH
  • 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 4026098
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:55:41+00:00 2026-05-20T10:55:41+00:00

In the book of The C++ Programming Language, the author gives the following example

  • 0

In the book of “The C++ Programming Language”, the author gives the following example and several claims.

class   Matrix {
   double  m[4][4];
   public:
      Matrix( );
      friend Matrix operator+(const  Matrix&, const Matrix&)
};

Matrix  operator+(const  Matrix& arg1, const Matrix& arg2)
{  
  Matrix sum;
  for (int i=0; i<4; i++)
  sum.m[i][j ]=arg1.m[i][j]+arg2.m[i][j];
  return sum;
 }

The book claims that

references allow the use of expressions involving the usual arithmetic operators for large objects without excessive copying. Pointers cannot be used because it is not possible to redefine the meaning of an operator applied to a pointer.

I do not understand what does “excessive copying” refer to in the above statement. And for the statement of “Pointers cannot be used because it is not possible to redefine the meaning of an operator applied to a pointer”, I am just totally lost. Thanks for the explanation.

  • 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-20T10:55:41+00:00Added an answer on May 20, 2026 at 10:55 am

    If operator+ was instead declared as taking its operands by value, e.g.,

    Matrix operator+(Matrix arg1, Matrix arg2)
    

    then copies of arg1 and arg2 would have to be made to be passed into the function. A simple matrix addition, e.g.,

    Matrix x, y;
    x + y;
    

    would require copies of both x and y to be made; effectively, you end up having to copy 32 doubles, which, while not extremely expensive in this case, is not particularly cheap either. When you take an argument by reference, no copy has to be made.

    Note that some operator overloads must take their argument by reference. As a common example, consider the << stream insertion operator: it must take its std::istream operand by reference because it is impossible to copy the stream.


    Pointers cannot be used because operators cannot be overloaded for pointers: at least one operand of each operator overload must be a class or enumeration type. Even if you could use pointers, the syntax would be very awkward; instead of using x + y as shown above, you would need to use &x + &y.

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

Sidebar

Related Questions

In the book of The C++ programming language, author gave the following example. He
I saw the following example in book of the C++ Programming Language class Ptr
In section 7.1.1 of the book The C++ Programming Language the author states: inline
In the book 'Code Complete' the author talks about programming into a language (instead
In the book The C Programming Language it says: Many of the functions in
I have been reading from the book The C Programming Language learning C, and
I bought The D Programming Language a little while ago. Great book, very educational.
I am reading PrenticeHall. The C Programming Language - 2nd Ed.Kernighan,Ritchie. In this book(pg-20)
In the book Programming Collective Intelligence I found the following function to compute the
In Bjarne Stroustrup's book The C++ Programming Language, it is stated that a derived

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.